Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
slightly better error handling/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Dec 21, 2023
1 parent 8af4c77 commit a1cc172
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MistralClient {
const options = {
method: method,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
},
Expand Down Expand Up @@ -104,14 +105,19 @@ class MistralClient {
}
return await response.json();
} else if (RETRY_STATUS_CODES.includes(response.status)) {
console.debug(`Retrying request, attempt: ${attempts + 1}`);
console.debug(
`Retrying request on response status: ${response.status}`,
`Response: ${await response.text()}`,
`Attempt: ${attempts + 1}`,
);
// eslint-disable-next-line max-len
await new Promise((resolve) =>
setTimeout(resolve, Math.pow(2, (attempts + 1)) * 500),
);
} else {
throw new MistralAPIError(
`HTTP error! status: ${response.status}`,
`HTTP error! status: ${response.status} ` +
`Response: \n${await response.text()}`,
);
}
} catch (error) {
Expand Down

0 comments on commit a1cc172

Please sign in to comment.