1
0
mirror of https://github.com/immich-app/immich.git synced 2025-01-26 17:21:29 +02:00

fix(server): handle failed ML responses (#4036)

* handle ml error responses

* more explicit error message

* formatting

* better formatting
This commit is contained in:
Mert 2023-09-09 05:03:59 -04:00 committed by GitHub
parent 258b98c262
commit 4b11e925d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,12 @@ export class MachineLearningRepository implements IMachineLearningRepository {
private async post<T>(url: string, input: TextModelInput | VisionModelInput, config: ModelConfig): Promise<T> { private async post<T>(url: string, input: TextModelInput | VisionModelInput, config: ModelConfig): Promise<T> {
const formData = await this.getFormData(input, config); const formData = await this.getFormData(input, config);
const res = await fetch(`${url}/predict`, { method: 'POST', body: formData }); const res = await fetch(`${url}/predict`, { method: 'POST', body: formData });
if (res.status >= 400) {
throw new Error(
`Request ${config.modelType ? `for ${config.modelType.replace('-', ' ')} ` : ''}` +
`failed with status ${res.status}: ${res.statusText}`,
);
}
return res.json(); return res.json();
} }