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
2023-03-25 17:32:59 +01:00
committed by GitHub
parent 3f09a4c355
commit b89ca2082e
5 changed files with 59 additions and 15 deletions
+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");
}