update error handler on API Call

This commit is contained in:
João Mendes 2023-02-20 00:59:43 +00:00
parent 9a108f01ce
commit 43b64982ab
1 changed files with 7 additions and 3 deletions

View File

@ -32,10 +32,14 @@ export const useChatGpt = (context: BaseComponentContext, appId:string, AzureFun
body: JSON.stringify({ prompt: query }),
method: "POST",
};
const response = await (await client()).post(AzureFunctionUrl, AadHttpClient.configurations.v1, options);
const answer = await response.json();
return answer.choices[0].text;
if (response.status === 200) {
return answer?.choices[0].text;
} else {
console.log("[getCompletion] error:", answer);
throw new Error("Error on executing the request, please try again later.");
}
} catch (error) {
if (!DEBUG) {
console.log("[getCompletion] error:", error);