feat: enhance error handling for LLM API calls

Add LLM error alert functionality to display specific error messages based on API responses. Introduce new LlmErrorAlertType interface for structured error alerts. Update chat components to manage and display LLM error alerts effectively, improving user feedback during error scenarios.
This commit is contained in:
xKevIsDev
2025-07-03 11:43:58 +01:00
committed by Roamin
parent 590363cf6e
commit 26c46088bc
6 changed files with 256 additions and 25 deletions

View File

@@ -375,16 +375,34 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
} catch (error: any) {
logger.error(error);
const errorResponse = {
error: true,
message: error.message || 'An unexpected error occurred',
statusCode: error.statusCode || 500,
isRetryable: error.isRetryable !== false, // Default to retryable unless explicitly false
provider: error.provider || 'unknown',
};
if (error.message?.includes('API key')) {
throw new Response('Invalid or missing API key', {
status: 401,
statusText: 'Unauthorized',
});
return new Response(
JSON.stringify({
...errorResponse,
message: 'Invalid or missing API key',
statusCode: 401,
isRetryable: false,
}),
{
status: 401,
headers: { 'Content-Type': 'application/json' },
statusText: 'Unauthorized',
},
);
}
throw new Response(null, {
status: 500,
statusText: 'Internal Server Error',
return new Response(JSON.stringify(errorResponse), {
status: errorResponse.statusCode,
headers: { 'Content-Type': 'application/json' },
statusText: 'Error',
});
}
}