Add context info to server error (#17663)
* fix: Add context info to server error * chore: update webui build output
This commit is contained in:
committed by
GitHub
parent
ed32089927
commit
cee92af553
@@ -764,18 +764,33 @@ export class ChatService {
|
||||
* @param response - HTTP response object
|
||||
* @returns Promise<Error> - Parsed error with context info if available
|
||||
*/
|
||||
private static async parseErrorResponse(response: Response): Promise<Error> {
|
||||
private static async parseErrorResponse(
|
||||
response: Response
|
||||
): Promise<Error & { contextInfo?: { n_prompt_tokens: number; n_ctx: number } }> {
|
||||
try {
|
||||
const errorText = await response.text();
|
||||
const errorData: ApiErrorResponse = JSON.parse(errorText);
|
||||
|
||||
const message = errorData.error?.message || 'Unknown server error';
|
||||
const error = new Error(message);
|
||||
const error = new Error(message) as Error & {
|
||||
contextInfo?: { n_prompt_tokens: number; n_ctx: number };
|
||||
};
|
||||
error.name = response.status === 400 ? 'ServerError' : 'HttpError';
|
||||
|
||||
if (errorData.error && 'n_prompt_tokens' in errorData.error && 'n_ctx' in errorData.error) {
|
||||
error.contextInfo = {
|
||||
n_prompt_tokens: errorData.error.n_prompt_tokens,
|
||||
n_ctx: errorData.error.n_ctx
|
||||
};
|
||||
}
|
||||
|
||||
return error;
|
||||
} catch {
|
||||
const fallback = new Error(`Server error (${response.status}): ${response.statusText}`);
|
||||
const fallback = new Error(
|
||||
`Server error (${response.status}): ${response.statusText}`
|
||||
) as Error & {
|
||||
contextInfo?: { n_prompt_tokens: number; n_ctx: number };
|
||||
};
|
||||
fallback.name = 'HttpError';
|
||||
return fallback;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user