fix error handling of core for mistral integration (#2672)

* fix error handling of core for mistral integration

* refactor logic using status code

* nitpicking fix

---------

Co-authored-by: Jack Tri Le <Jack>
This commit is contained in:
Inchoker 2024-04-10 17:03:26 +07:00 committed by GitHub
parent 3f23de6c28
commit 00049aac7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()