2024-02-27 03:48:47 +01:00
|
|
|
import { isHttpError } from '@immich/sdk';
|
2024-02-14 17:24:18 +01:00
|
|
|
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
|
2022-12-26 16:35:52 +01:00
|
|
|
|
2024-02-29 17:22:39 +01:00
|
|
|
export function getServerErrorMessage(error: unknown) {
|
2024-02-27 03:48:47 +01:00
|
|
|
if (isHttpError(error)) {
|
2024-02-29 17:22:39 +01:00
|
|
|
return error.data?.message || error.message;
|
2024-02-27 03:48:47 +01:00
|
|
|
}
|
2023-07-15 06:03:56 +02:00
|
|
|
}
|
|
|
|
|
2024-02-27 17:37:37 +01:00
|
|
|
export function handleError(error: unknown, message: string) {
|
2024-02-14 17:24:18 +01:00
|
|
|
if ((error as Error)?.name === 'AbortError') {
|
2023-07-15 06:03:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-02-16 22:31:22 +01:00
|
|
|
console.error(`[handleError]: ${message}`, error, (error as Error)?.stack);
|
2023-07-15 06:03:56 +02:00
|
|
|
|
2024-02-29 17:22:39 +01:00
|
|
|
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
|
|
|
|
2024-02-29 17:22:39 +01:00
|
|
|
notificationController.show({
|
|
|
|
message: serverMessage || message,
|
|
|
|
type: NotificationType.Error,
|
2024-02-27 17:37:37 +01:00
|
|
|
});
|
2024-02-29 17:22:39 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2022-12-26 16:35:52 +01:00
|
|
|
}
|