mirror of
https://github.com/immich-app/immich.git
synced 2025-11-19 08:02:37 +09:00
fix(web): fetch error reporting (#7391)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user