mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 02:13:51 -04:00
* no-misused-promises * no-floating-promises * format * revert for now * remove load function * require-await * revert a few no-floating-promises changes that would cause no-misused-promises failures * format * fix a few more * fix most remaining errors * executor-queue * executor-queue.spec * remove duplicate comments by grouping rules * upgrade sveltekit and enforce rules * oops. move await * try this * just ignore for now since it's only a test * run in parallel * Update web/src/routes/admin/jobs-status/+page.svelte Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> * remove Promise.resolve call * rename function * remove unnecessary warning silencing * make handleError sync * fix new errors from recently merged PR to main * extract method * use handlePromiseError --------- Co-authored-by: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { isHttpError } from '@immich/sdk';
|
|
import { isAxiosError } from 'axios';
|
|
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
|
|
|
|
export async 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;
|
|
}
|
|
}
|
|
|
|
export function handleError(error: unknown, message: string) {
|
|
if ((error as Error)?.name === 'AbortError') {
|
|
return;
|
|
}
|
|
|
|
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)`;
|
|
}
|
|
|
|
notificationController.show({
|
|
message: serverMessage || message,
|
|
type: NotificationType.Error,
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
console.error(error);
|
|
});
|
|
}
|