Skip to content

Commit

Permalink
PDE-5774 fix(core): Catch HTTP 500 along with status codes >500 in RP…
Browse files Browse the repository at this point in the history
…C client (#974)

* HTTP 500 is no longer expected

* fix test

* update test logic
  • Loading branch information
rnegron authored Feb 20, 2025
1 parent 061f030 commit 051bfff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/tools/create-rpc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const createRpcClient = (event) => {
try {
res = await request(req);

if (res.status > 500) {
if (res.status >= 500) {
throw new Error('Unable to reach the RPC server');
}
if (res.content) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/tools/mocky.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ const mockRpcGetPresignedPostCall = (key) => {
});
};

const mockRpcFail = (error) => {
const mockRpcFail = (error, status = 400) => {
nock(FAKE_ZAPIER_URL)
.post(RPC_URL_PATH)
.reply(500, (uri, requestBody) => {
.reply(status, (uri, requestBody) => {
const id = JSON.parse(requestBody).id;
return { error, id };
});
Expand Down
8 changes: 4 additions & 4 deletions packages/core/test/tools/rpc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ describe('rpc client', () => {

it('should handle an explosion', () => {
// mock 3 explosions due to retry
mocky.mockRpcFail('this is an expected explosion');
mocky.mockRpcFail('this is an expected explosion');
mocky.mockRpcFail('this is an expected explosion');
mocky.mockRpcFail('this is an expected explosion', 500);
mocky.mockRpcFail('this is an expected explosion', 500);
mocky.mockRpcFail('this is an expected explosion', 500);

return rpc('explode')
.then(() => {
throw new Error('this should have exploded');
})
.catch((err) => {
err.message.should.eql(
'RPC request failed after 3 attempts: this is an expected explosion',
'RPC request failed after 3 attempts: Unable to reach the RPC server',
);
});
});
Expand Down

0 comments on commit 051bfff

Please sign in to comment.