Skip to content

Commit

Permalink
Handle server error
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Nov 10, 2023
1 parent 97b8d06 commit 468f1de
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/server/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,25 @@ export const getAgentResponse: GetAgentResponse<AgentPayload> = async (
throw new HttpError(401);
}

const payload = {
conversation: conversation,
};

const payload = { conversation: conversation };
try {
const response = await fetch(`${ADS_SERVER_URL}/chat`, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});

const json = (await response.json()) as OpenAIResponse; // this should be AzureOpenAIResponse
return {
content: json
const json = await response.json() as { detail?: string }; // Parse JSON once

if (!response.ok) {
const errorMsg = json.detail || `HTTP error with status code ${response.status}`;
console.error('Server Error:', errorMsg);
throw new Error(errorMsg);
}

return { content: json };

} catch (error: any) {
console.error(error);
throw new HttpError(500, 'Something went wrong. Please try again later');
}

throw new HttpError(500, 'Something went wrong');
};

0 comments on commit 468f1de

Please sign in to comment.