fix(server): http error parsing on endpoints without a default response (#12927)

This commit is contained in:
Jason Rasmussen 2024-09-25 12:05:03 -04:00 committed by GitHub
parent 8d515adac5
commit 005528ab5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 162 additions and 18 deletions

View file

@ -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) {