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

Commit

Permalink
Merge pull request #25 from mistralai/bam4d/error_handling
Browse files Browse the repository at this point in the history
slightly better error handling/logging
  • Loading branch information
Bam4d authored Dec 21, 2023
2 parents bdf90cb + a1cc172 commit 14228e4
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 14228e4

Please sign in to comment.