Improve error handling of invalid bodies
This commit is contained in:
parent
86ec8492e8
commit
25e864a863
1 changed files with 27 additions and 14 deletions
|
@ -351,23 +351,31 @@ async function _promiseAjax(
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: Response;
|
let response: Response;
|
||||||
let result: string | Uint8Array | Readable | unknown;
|
|
||||||
try {
|
try {
|
||||||
response = socketManager
|
response = socketManager
|
||||||
? await socketManager.fetch(url, fetchOptions)
|
? await socketManager.fetch(url, fetchOptions)
|
||||||
: await fetch(url, fetchOptions);
|
: await fetch(url, fetchOptions);
|
||||||
if (
|
} catch (e) {
|
||||||
options.serverUrl &&
|
log.error(logId, 0, 'Error');
|
||||||
getHostname(options.serverUrl) === getHostname(url)
|
const stack = `${e.stack}\nInitial stack:\n${options.stack}`;
|
||||||
) {
|
throw makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack);
|
||||||
await handleStatusCode(response.status);
|
}
|
||||||
|
|
||||||
if (!unauthenticated && response.status === 401) {
|
if (
|
||||||
log.error('Got 401 from Signal Server. We might be unlinked.');
|
options.serverUrl &&
|
||||||
window.Whisper.events.trigger('mightBeUnlinked');
|
getHostname(options.serverUrl) === getHostname(url)
|
||||||
}
|
) {
|
||||||
|
await handleStatusCode(response.status);
|
||||||
|
|
||||||
|
if (!unauthenticated && response.status === 401) {
|
||||||
|
log.error('Got 401 from Signal Server. We might be unlinked.');
|
||||||
|
window.Whisper.events.trigger('mightBeUnlinked');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let result: string | Uint8Array | Readable | unknown;
|
||||||
|
try {
|
||||||
if (DEBUG && !isSuccess(response.status)) {
|
if (DEBUG && !isSuccess(response.status)) {
|
||||||
result = await response.text();
|
result = await response.text();
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -391,10 +399,15 @@ async function _promiseAjax(
|
||||||
} else {
|
} else {
|
||||||
result = await response.textConverted();
|
result = await response.textConverted();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
log.error(logId, 0, 'Error');
|
log.error(logId, response.status, 'Error');
|
||||||
const stack = `${e.stack}\nInitial stack:\n${options.stack}`;
|
const stack = `${error.stack}\nInitial stack:\n${options.stack}`;
|
||||||
throw makeHTTPError('promiseAjax catch', 0, {}, e.toString(), stack);
|
throw makeHTTPError(
|
||||||
|
`promiseAjax: error parsing body (Content-Type: ${response.headers.get('content-type')})`,
|
||||||
|
response.status,
|
||||||
|
response.headers.raw(),
|
||||||
|
stack
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSuccess(response.status)) {
|
if (!isSuccess(response.status)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue