0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-21 00:52:43 -05:00

fix(web): handle non-http client side page error (#8901)

handle non-http client side page error
This commit is contained in:
Nguyễn Hoàng Đức 2024-04-24 19:32:00 +07:00 committed by GitHub
parent 99ccf28bc6
commit aac789f788
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,9 @@
import { isHttpError } from '@immich/sdk';
import { isHttpError, type ApiHttpError } from '@immich/sdk';
import type { HandleClientError } from '@sveltejs/kit';
const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';
const parseError = (error: unknown) => {
const httpError = isHttpError(error) ? error : undefined;
const parseHTTPError = (httpError: ApiHttpError) => {
const statusCode = httpError?.status || httpError?.data?.statusCode || 500;
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 result = parseError(error);
const parseError = (error: unknown, status: number, message: string) => {
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}`);
return result;
};