Skip to content

Commit

Permalink
fix error handling of core for mistral integration (janhq#2672)
Browse files Browse the repository at this point in the history
* fix error handling of core for mistral integration

* refactor logic using status code

* nitpicking fix

---------

Co-authored-by: Jack Tri Le <Jack>
  • Loading branch information
Inchoker authored Apr 10, 2024
1 parent 3f23de6 commit 00049aa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/browser/extensions/engines/helpers/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ export function requestInference(
.then(async (response) => {
if (!response.ok) {
const data = await response.json()
let errorCode = ErrorCode.Unknown;
if (data.error) {
errorCode = data.error.code ?? data.error.type ?? ErrorCode.Unknown
} else if (response.status === 401) {
errorCode = ErrorCode.InvalidApiKey;
}
const error = {
message: data.error?.message ?? 'Error occurred.',
code: data.error?.code ?? data.error?.type ?? ErrorCode.Unknown,
code: errorCode,
}
subscriber.error(error)
subscriber.complete()
Expand Down

0 comments on commit 00049aa

Please sign in to comment.