mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix(web): fetch error reporting (#7391)
This commit is contained in:
parent
8a05ff51e9
commit
c8bdeb8fec
4 changed files with 43 additions and 32 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue