mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
* fix: throw a typed error on malformed api responses * fix: drop response body parse check * fix(web): keep json response validation when overriding fetch (#31008) * fix(cli): report malformed api responses (#31007)
43 lines
972 B
TypeScript
43 lines
972 B
TypeScript
import { HttpError } from '@oazapfts/runtime';
|
|
|
|
export interface ApiValidationError {
|
|
code: string;
|
|
path: (string | number)[];
|
|
message: string;
|
|
}
|
|
|
|
export interface ApiExceptionResponse {
|
|
message: string;
|
|
error?: string;
|
|
statusCode: number;
|
|
errors?: ApiValidationError[];
|
|
}
|
|
|
|
export interface ApiHttpError extends HttpError {
|
|
data: ApiExceptionResponse;
|
|
}
|
|
|
|
export function isHttpError(error: unknown): error is ApiHttpError {
|
|
return error instanceof HttpError;
|
|
}
|
|
|
|
export class MalformedResponseError extends Error {
|
|
override name = 'MalformedResponseError';
|
|
|
|
constructor(
|
|
reason: string,
|
|
readonly url: string,
|
|
readonly status: number,
|
|
readonly contentType: string | null,
|
|
) {
|
|
super(
|
|
`${reason} (${url}, HTTP ${status}, content-type: ${contentType ?? 'none'})`,
|
|
);
|
|
}
|
|
}
|
|
|
|
export function isMalformedResponseError(
|
|
error: unknown,
|
|
): error is MalformedResponseError {
|
|
return error instanceof MalformedResponseError;
|
|
}
|