update error handler on API Call
This commit is contained in:
parent
9a108f01ce
commit
43b64982ab
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue