rebase rework
This commit is contained in:
@@ -15,11 +15,20 @@ const API_BASE_URL = '/api';
|
||||
// @POST: Returned error contains message and status fields.
|
||||
async function buildApiError(response) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
const message = errorData.detail
|
||||
? (typeof errorData.detail === 'string' ? errorData.detail : JSON.stringify(errorData.detail))
|
||||
const detail = errorData?.detail;
|
||||
const message = detail
|
||||
? (
|
||||
typeof detail === 'string'
|
||||
? detail
|
||||
: (typeof detail?.message === 'string' ? detail.message : JSON.stringify(detail))
|
||||
)
|
||||
: `API request failed with status ${response.status}`;
|
||||
const error = new Error(message);
|
||||
error.status = response.status;
|
||||
/** @type {any} */ (error).status = response.status;
|
||||
/** @type {any} */ (error).detail = detail;
|
||||
if (detail && typeof detail === 'object' && detail.error_code) {
|
||||
/** @type {any} */ (error).error_code = String(detail.error_code);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
// [/DEF:buildApiError:Function]
|
||||
@@ -54,7 +63,18 @@ function shouldSuppressApiErrorToast(endpoint, error) {
|
||||
(error?.status === 400 || error?.status === 404) &&
|
||||
/Repository for dashboard .* not found/i.test(String(error?.message || ''));
|
||||
|
||||
return isGitStatusEndpoint && isNoRepoError;
|
||||
const isGitPullEndpoint =
|
||||
typeof endpoint === 'string' &&
|
||||
endpoint.startsWith('/git/repositories/') &&
|
||||
endpoint.endsWith('/pull');
|
||||
const isUnfinishedMergeError =
|
||||
error?.status === 409 &&
|
||||
(
|
||||
String(error?.error_code || '') === 'GIT_UNFINISHED_MERGE' ||
|
||||
String(error?.detail?.error_code || '') === 'GIT_UNFINISHED_MERGE'
|
||||
);
|
||||
|
||||
return (isGitStatusEndpoint && isNoRepoError) || (isGitPullEndpoint && isUnfinishedMergeError);
|
||||
}
|
||||
// [/DEF:shouldSuppressApiErrorToast:Function]
|
||||
|
||||
@@ -130,7 +150,7 @@ async function fetchApiBlob(endpoint, options = {}) {
|
||||
if (response.status === 202) {
|
||||
const payload = await response.json().catch(() => ({ message: "Resource is being prepared" }));
|
||||
const error = new Error(payload?.message || "Resource is being prepared");
|
||||
error.status = 202;
|
||||
/** @type {any} */ (error).status = 202;
|
||||
throw error;
|
||||
}
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user