mirror of
https://github.com/RoboSats/robosats.git
synced 2025-02-21 12:49:02 +00:00
Fix HTTP status errors on Android (#384)
* Capture HTTP errors on Anrdoid * Lint * Inclode code
This commit is contained in:
parent
57a47a408c
commit
c3183c73af
@ -53,6 +53,23 @@ const App = () => {
|
|||||||
loadCookie('garage').then(() => injectMessageResolve(reponseId));
|
loadCookie('garage').then(() => injectMessageResolve(reponseId));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onCatch = (dataId: string, event: any) => {
|
||||||
|
let json = '{}';
|
||||||
|
let code = 500;
|
||||||
|
if (event.message) {
|
||||||
|
const reponse = /Request Response Code \((?<code>\d*)\)\: (?<json>\{.*\})/.exec(
|
||||||
|
event.message,
|
||||||
|
);
|
||||||
|
json = reponse?.groups?.json ?? '{}';
|
||||||
|
code = reponse?.groups?.code ? parseInt(reponse?.groups?.code) : 500;
|
||||||
|
}
|
||||||
|
injectMessageResolve(dataId, {
|
||||||
|
headers: {},
|
||||||
|
respCode: code,
|
||||||
|
json: JSON.parse(json),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const onMessage = async (event: WebViewMessageEvent) => {
|
const onMessage = async (event: WebViewMessageEvent) => {
|
||||||
const data = JSON.parse(event.nativeEvent.data);
|
const data = JSON.parse(event.nativeEvent.data);
|
||||||
if (data.category === 'http') {
|
if (data.category === 'http') {
|
||||||
@ -63,7 +80,7 @@ const App = () => {
|
|||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
.catch(sendTorStatus)
|
.catch((e) => onCatch(data.id, e))
|
||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'post') {
|
} else if (data.type === 'post') {
|
||||||
torClient
|
torClient
|
||||||
@ -71,7 +88,7 @@ const App = () => {
|
|||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
.catch(sendTorStatus)
|
.catch((e) => onCatch(data.id, e))
|
||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'delete') {
|
} else if (data.type === 'delete') {
|
||||||
torClient
|
torClient
|
||||||
@ -79,7 +96,7 @@ const App = () => {
|
|||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
.catch(sendTorStatus)
|
.catch((e) => onCatch(data.id, e))
|
||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
} else if (data.type === 'xhr') {
|
} else if (data.type === 'xhr') {
|
||||||
torClient
|
torClient
|
||||||
@ -87,7 +104,7 @@ const App = () => {
|
|||||||
.then((response: object) => {
|
.then((response: object) => {
|
||||||
injectMessageResolve(data.id, response);
|
injectMessageResolve(data.id, response);
|
||||||
})
|
})
|
||||||
.catch(sendTorStatus)
|
.catch((e) => onCatch(data.id, e))
|
||||||
.finally(sendTorStatus);
|
.finally(sendTorStatus);
|
||||||
}
|
}
|
||||||
} else if (data.category === 'system') {
|
} else if (data.category === 'system') {
|
||||||
@ -116,7 +133,7 @@ const App = () => {
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendTorStatus = async () => {
|
const sendTorStatus = async (event?: any) => {
|
||||||
NetInfo.fetch().then(async (state) => {
|
NetInfo.fetch().then(async (state) => {
|
||||||
let daemonStatus = 'ERROR';
|
let daemonStatus = 'ERROR';
|
||||||
if (state.isInternetReachable) {
|
if (state.isInternetReachable) {
|
||||||
|
Loading…
Reference in New Issue
Block a user