mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
fix(server): http error parsing on endpoints without a default response (#12927)
This commit is contained in:
parent
8d515adac5
commit
005528ab5e
13 changed files with 162 additions and 18 deletions
|
|
@ -2,9 +2,21 @@ import { isHttpError } from '@immich/sdk';
|
|||
import { notificationController, NotificationType } from '../components/shared-components/notification/notification';
|
||||
|
||||
export function getServerErrorMessage(error: unknown) {
|
||||
if (isHttpError(error)) {
|
||||
return error.data?.message || error.message;
|
||||
if (!isHttpError(error)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// errors for endpoints without return types aren't parsed as json
|
||||
let data = error.data;
|
||||
if (typeof data === 'string') {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch {
|
||||
// Not a JSON string
|
||||
}
|
||||
}
|
||||
|
||||
return data?.message || error.message;
|
||||
}
|
||||
|
||||
export function handleError(error: unknown, message: string) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue