forked from Cutlery/immich
		
	chore(server): better ML error messages (#5914)
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
		
							parent
							
								
									4f6f79a392
								
							
						
					
					
						commit
						13ba83dce6
					
				| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user