mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
refactor(web): drop axios (#7490)
* refactor: downloadApi * refactor: assetApi * chore: drop axios * chore: tidy up * chore: fix exports * fix: show notification when download starts
This commit is contained in:
parent
bb3d81bfc5
commit
09a7291527
37 changed files with 217 additions and 20671 deletions
|
|
@ -1,24 +1,9 @@
|
|||
import { isHttpError } from '@immich/sdk';
|
||||
import { isAxiosError } from 'axios';
|
||||
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
|
||||
|
||||
export async function getServerErrorMessage(error: unknown) {
|
||||
export function getServerErrorMessage(error: unknown) {
|
||||
if (isHttpError(error)) {
|
||||
return error.data?.message || error.data;
|
||||
}
|
||||
|
||||
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;
|
||||
return error.data?.message || error.message;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,18 +14,17 @@ export function handleError(error: unknown, message: string) {
|
|||
|
||||
console.error(`[handleError]: ${message}`, error, (error as Error)?.stack);
|
||||
|
||||
getServerErrorMessage(error)
|
||||
.then((serverMessage) => {
|
||||
if (serverMessage) {
|
||||
serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`;
|
||||
}
|
||||
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);
|
||||
notificationController.show({
|
||||
message: serverMessage || message,
|
||||
type: NotificationType.Error,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue