Skip to content

Commit

Permalink
fix(api): improve error message with EAI_AGAIN and ECONNRESET
Browse files Browse the repository at this point in the history
When the clever-tools were using the `request.superagent` from the clever-client,
`EAI_AGAIN` and `ECONNRESET` errors were caught, and message were improved.
When we moved to the common request.fetch, we lost improvment.
This commit adds back the improved messages but in the clever-tools code.
  • Loading branch information
hsablonniere committed Feb 6, 2024
1 parent 676a598 commit b134213
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/models/send-to-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ async function sendToApi (requestParams) {
}
return requestParams;
})
.then((requestParams) => request(requestParams, { retry: 1 }));
.then((requestParams) => request(requestParams, { retry: 1 }))
.catch(processError);
}

function processError (error) {
const code = error.code ?? error?.cause?.code;
if (code === 'EAI_AGAIN') {
throw new Error('Cannot reach the Clever Cloud API, please check your internet connection.', { cause: error });
}
if (code === 'ECONNRESET') {
throw new Error('The connection to the Clever Cloud API was closed abruptly, please try again.', { cause: error });
}
throw error;
}

function sendToWarp10 (requestParams) {
Expand All @@ -45,4 +57,4 @@ async function getHostAndTokens () {
};
}

module.exports = { sendToApi, sendToWarp10, getHostAndTokens };
module.exports = { sendToApi, sendToWarp10, getHostAndTokens, processError };

0 comments on commit b134213

Please sign in to comment.