fix(web): fetch error reporting (#7391)

This commit is contained in:
Michel Heusschen 2024-02-27 03:48:47 +01:00 committed by GitHub
parent 8a05ff51e9
commit c8bdeb8fec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 32 deletions

View file

@ -1,18 +1,25 @@
import type { HttpError } from '@sveltejs/kit';
import { isHttpError } from '@immich/sdk';
import { isAxiosError } from 'axios';
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
export async function getServerErrorMessage(error: unknown) {
let data = (error as HttpError)?.body;
if (data instanceof Blob) {
const response = await data.text();
try {
data = JSON.parse(response);
} catch {
data = { message: response };
}
if (isHttpError(error)) {
return error.data?.message || error.data;
}
return data?.message || null;
if (isAxiosError(error)) {
let data = error.response?.data;
if (data instanceof Blob) {
const response = await data.text();
try {
data = JSON.parse(response);
} catch {
data = { message: response };
}
}
return data?.message;
}
}
export async function handleError(error: unknown, message: string) {