immich/web/src/lib/utils/handle-error.ts
Jason Rasmussen ad343b7b32
refactor(server): download assets (#3032)
* refactor: download assets

* chore: open api

* chore: finish tests, make size configurable

* chore: defualt to 4GiB

* chore: open api

* fix: optional archive size

* fix: bugs

* chore: cleanup
2023-06-30 11:24:28 -05:00

30 lines
740 B
TypeScript

import type { ApiError } from '@api';
import {
notificationController,
NotificationType
} from '../components/shared-components/notification/notification';
export async function handleError(error: unknown, message: string) {
console.error(`[handleError]: ${message}`, error);
let data = (error as ApiError)?.response?.data;
if (data instanceof Blob) {
const response = await data.text();
try {
data = JSON.parse(response);
} catch {
data = { message: response };
}
}
let serverMessage = data?.message;
if (serverMessage) {
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
}
notificationController.show({
message: serverMessage || message,
type: NotificationType.Error
});
}