mirror of
https://github.com/immich-app/immich.git
synced 2025-07-07 10:17:05 -04:00
fix(web): handle non-http client side page error (#8901)
handle non-http client side page error
This commit is contained in:
parent
99ccf28bc6
commit
aac789f788
@ -1,10 +1,9 @@
|
|||||||
import { isHttpError } from '@immich/sdk';
|
import { isHttpError, type ApiHttpError } from '@immich/sdk';
|
||||||
import type { HandleClientError } from '@sveltejs/kit';
|
import type { HandleClientError } from '@sveltejs/kit';
|
||||||
|
|
||||||
const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';
|
const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';
|
||||||
|
|
||||||
const parseError = (error: unknown) => {
|
const parseHTTPError = (httpError: ApiHttpError) => {
|
||||||
const httpError = isHttpError(error) ? error : undefined;
|
|
||||||
const statusCode = httpError?.status || httpError?.data?.statusCode || 500;
|
const statusCode = httpError?.status || httpError?.data?.statusCode || 500;
|
||||||
const message = httpError?.data?.message || (httpError?.data && String(httpError.data)) || httpError?.message;
|
const message = httpError?.data?.message || (httpError?.data && String(httpError.data)) || httpError?.message;
|
||||||
|
|
||||||
@ -20,8 +19,19 @@ const parseError = (error: unknown) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleError: HandleClientError = ({ error }) => {
|
const parseError = (error: unknown, status: number, message: string) => {
|
||||||
const result = parseError(error);
|
if (isHttpError(error)) {
|
||||||
|
return parseHTTPError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: message || DEFAULT_MESSAGE,
|
||||||
|
code: status,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const handleError: HandleClientError = ({ error, status, message }) => {
|
||||||
|
const result = parseError(error, status, message);
|
||||||
console.error(`[hooks.client.ts]:handleError ${result.message}`);
|
console.error(`[hooks.client.ts]:handleError ${result.message}`);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user