Skip to content

Commit

Permalink
fix: error handling in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Apr 4, 2024
1 parent c8e7b56 commit 9f53ec7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"preLaunchTask": "func: host start"
}
]
}
}
17 changes: 11 additions & 6 deletions packages/webapp/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ export async function getCompletion(options: ChatRequestOptions) {
}),
});

if (options.stream) {
return getChunksFromResponse<ChatResponseChunk>(response, options.chunkIntervalMs);
if (response.status > 299 || !response.ok) {
let json: ChatResponse | undefined;
try {
json = await response.json();
} catch {}

const error = json?.error ?? response.statusText;
throw new Error(error);
}

const json: ChatResponse = await response.json();
if (response.status > 299 || !response.ok) {
throw new Error(json.error ?? 'Unknown error');
if (options.stream) {
return getChunksFromResponse<ChatResponseChunk>(response, options.chunkIntervalMs);
}

return json;
return response.json();
}

export function getCitationUrl(citation: string): string {
Expand Down

0 comments on commit 9f53ec7

Please sign in to comment.