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

20 lines
556 B
TypeScript
Raw Normal View History

import { ApiError } from '../../api';
import {
notificationController,
NotificationType
} from '../components/shared-components/notification/notification';
export function handleError(error: unknown, message: string) {
console.error(`[handleError]: ${message}`, error);
2023-01-13 23:04:59 +01:00
let serverMessage = (error as ApiError)?.response?.data?.message;
if (serverMessage) {
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
2023-01-13 23:04:59 +01:00
}
notificationController.show({
2023-01-13 23:04:59 +01:00
message: serverMessage || message,
type: NotificationType.Error
});
}