mirror of
https://github.com/immich-app/immich.git
synced 2025-01-10 05:46:46 +01:00
09a7291527
* refactor: downloadApi * refactor: assetApi * chore: drop axios * chore: tidy up * chore: fix exports * fix: show notification when download starts
30 lines
861 B
TypeScript
30 lines
861 B
TypeScript
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;
|
|
}
|
|
|
|
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)`;
|
|
}
|
|
|
|
notificationController.show({
|
|
message: serverMessage || message,
|
|
type: NotificationType.Error,
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|