Improved network debugging
This commit is contained in:
@@ -9,6 +9,7 @@ import Logger from "./Logger";
|
||||
import download from "./download";
|
||||
import {
|
||||
AuthorizationError,
|
||||
BadGatewayError,
|
||||
BadRequestError,
|
||||
NetworkError,
|
||||
NotFoundError,
|
||||
@@ -101,6 +102,7 @@ class ApiClient {
|
||||
}
|
||||
|
||||
let response;
|
||||
const timeStart = window.performance.now();
|
||||
|
||||
try {
|
||||
response = await fetchWithRetry(urlToFetch, {
|
||||
@@ -127,6 +129,7 @@ class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
const timeEnd = window.performance.now();
|
||||
const success = response.status >= 200 && response.status < 300;
|
||||
|
||||
if (options.download && success) {
|
||||
@@ -196,6 +199,12 @@ class ApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
if (response.status === 502) {
|
||||
throw new BadGatewayError(
|
||||
`Request to ${urlToFetch} failed in ${timeEnd - timeStart}ms.`
|
||||
);
|
||||
}
|
||||
|
||||
const err = new RequestError(`Error ${response.status}`);
|
||||
Logger.error("Request failed", err, {
|
||||
...error,
|
||||
|
||||
Reference in New Issue
Block a user