Precise error messages (#150)

* Introduce a component to display error messages

* precise error message when api key is invalid
This commit is contained in:
Thomas LÉVEIL authored and GitHub committed 2023-03-25 10:32:59 -06:00
1 parent 3f09a4c355
commit b89ca2082e
5 files changed
+59 -15

No files matched your search

+10 -1
View File
@@ -17,7 +17,16 @@ const handler = async (req: Request): Promise<Response> => {
}
});
if (response.status !== 200) {
if (response.status === 401) {
return new Response(
response.body,
{
status: 500,
headers: response.headers
}
);
} else if (response.status !== 200) {
console.error(`OpenAI API returned an error ${response.status}: ${await response.text()}`)
throw new Error("OpenAI API returned an error");
}