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:
parent
99ccf28bc6
commit
aac789f788
1 changed files with 15 additions and 5 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue