0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-21 00:52:43 -05:00
immich/web/src/hooks.client.ts
Ben McCann 907a95a746
chore(web): cleanup promise handling (#7382)
* 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>
2024-02-27 10:37:37 -06:00

27 lines
870 B
TypeScript

import { isHttpError } from '@immich/sdk';
import type { HandleClientError } from '@sveltejs/kit';
const DEFAULT_MESSAGE = 'Hmm, not sure about that. Check the logs or open a ticket?';
const parseError = (error: unknown) => {
const httpError = isHttpError(error) ? error : undefined;
const statusCode = httpError?.status || httpError?.data?.statusCode || 500;
const message = httpError?.data?.message || (httpError?.data && String(httpError.data)) || httpError?.message;
console.log({
status: statusCode,
response: httpError?.data || 'No data',
});
return {
message: message || DEFAULT_MESSAGE,
code: statusCode,
stack: httpError?.stack,
};
};
export const handleError: HandleClientError = ({ error }) => {
const result = parseError(error);
console.error(`[hooks.client.ts]:handleError ${result.message}`);
return result;
};