2023-06-02 15:55:08 +02:00
|
|
|
import type { ApiError } from '@api';
|
2022-12-26 16:35:52 +01:00
|
|
|
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) {
|
2023-06-01 12:32:51 +02:00
|
|
|
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
|
2023-01-13 23:04:59 +01:00
|
|
|
}
|
|
|
|
|
2022-12-26 16:35:52 +01:00
|
|
|
notificationController.show({
|
2023-01-13 23:04:59 +01:00
|
|
|
message: serverMessage || message,
|
2022-12-26 16:35:52 +01:00
|
|
|
type: NotificationType.Error
|
|
|
|
});
|
|
|
|
}
|