mirror of
https://github.com/immich-app/immich.git
synced 2025-01-06 11:56:46 +01:00
chore(server): better ML error messages (#5914)
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
parent
4f6f79a392
commit
13ba83dce6
1 changed files with 9 additions and 5 deletions
|
@ -12,16 +12,20 @@ import {
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { readFile } from 'fs/promises';
|
import { readFile } from 'fs/promises';
|
||||||
|
|
||||||
|
const errorPrefix = 'Machine learning request';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MachineLearningRepository implements IMachineLearningRepository {
|
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 }).catch((error: Error | any) => {
|
||||||
|
throw new Error(`${errorPrefix} to "${url}" failed with ${error?.cause || error}`);
|
||||||
|
});
|
||||||
|
|
||||||
if (res.status >= 400) {
|
if (res.status >= 400) {
|
||||||
throw new Error(
|
const modelType = config.modelType ? ` for ${config.modelType.replace('-', ' ')}` : '';
|
||||||
`Request ${config.modelType ? `for ${config.modelType.replace('-', ' ')} ` : ''}` +
|
throw new Error(`${errorPrefix}${modelType} failed with status ${res.status}: ${res.statusText}`);
|
||||||
`failed with status ${res.status}: ${res.statusText}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue