1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 05:46:46 +01:00
immich/web/src/lib/utils/handle-error.ts

31 lines
861 B
TypeScript
Raw Normal View History

import { isHttpError } from '@immich/sdk';
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
export function getServerErrorMessage(error: unknown) {
if (isHttpError(error)) {
return error.data?.message || error.message;
}
}
export function handleError(error: unknown, message: string) {
if ((error as Error)?.name === 'AbortError') {
return;
}
2024-02-16 22:31:22 +01:00
console.error(`[handleError]: ${message}`, error, (error as Error)?.stack);
try {
let serverMessage = getServerErrorMessage(error);
if (serverMessage) {
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
}
2023-01-13 23:04:59 +01:00
notificationController.show({
message: serverMessage || message,
type: NotificationType.Error,
});
} catch (error) {
console.error(error);
}
}