Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ _Numbers show: (1) The URL and method of the REST API resource, (2) the HTTP cal
Notice: See [Known Limitations](#known-limitations) about `Delay` value.
- `Call Count` - the field should be used only in pair with `Delay`, default to 1.
- `jsonataResponseValidator` - This works in coordination with the `enableRebound` configuration to throw a status code 429. When this JSONata configuration is present and `enableRebound` set to `true`, it is assumed the JSONata will resolve to a boolean. If the boolean is false the incoming component message will be requeued and tried again. Otherwise the response will be processed as it normally would.
- `httpReboundErrorCodes` - Array of error status codes from the API response object which will cause the request to be put in the rebound queue. Messages in the rebound queue will be retried at a progressively longer interval (15 sec, 30 sec, 1 min, 2 min, 4 min, 8 min, etc.). Setting this value will override default values [408, 423, 429, 500, 502, 503, 504]. You should include those status codes unless you have a reason not to.
- `Request timeout` - Timeout period in milliseconds (1-1140000) while component waiting for server response, also can be configured with REQUEST_TIMEOUT environment variable if configuration field is not provided. Defaults to 100000 (100 sec).

Notice: Specified for component REQUEST_TIMEOUT enviroment variable would be overwritten by specified value of Request timeout, default value would be also overwritten
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports.processMethod = async function (msg, cfg, snapshot) {
msg.data.oihsnapshot = snapshot;
}

const { jsonataResponseValidator } = cfg;
const { jsonataResponseValidator, httpReboundErrorCodes } = cfg;
const config = cfg.reader;

if (!config.url) {
Expand Down Expand Up @@ -478,10 +478,12 @@ module.exports.processMethod = async function (msg, cfg, snapshot) {
}

async function buildErrorStructure(e) {
const reboundErrorCodes = httpReboundErrorCodes ? new Set(httpReboundErrorCodes) : HTTP_ERROR_CODE_REBOUND;
emitter.logger.debug(`Configured http error status codes for rebound are ${Array.from(reboundErrorCodes.values())}`);
if (
e.response
&& cfg.enableRebound
&& (HTTP_ERROR_CODE_REBOUND.has(e.response.status)
&& (reboundErrorCodes.has(e.response.status)
|| e.message.includes('DNS lookup timeout'))
) {
emitter.logger.info('Component error: %o', e);
Expand Down
31 changes: 31 additions & 0 deletions test/httpRequestAction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,37 @@ describe('httpRequest action', () => {
'JSONata validation against response failed and request should be retried in rebound queue',
);
});

it('add 404 to rebound status code list && enableRebound true', async () => {
const method = 'POST';
const msg = {
data: {
url: 'http://example.com',
},
};

const cfg = {
enableRebound: true,
httpReboundErrorCodes: [408, 404, 423, 429, 500, 502, 503, 504],
reader: {
url: '$$.data.url',
method,
},
auth: {},
};

nock(transform(msg, { customMapping: cfg.reader.url }))
.intercept('/', method)
.delay(20 + Math.random() * 200)
.reply(404);


await processAction.call(emitter, msg, cfg);
expect(emitter.emit.withArgs('rebound').callCount).to.be.equal(1);
expect(emitter.emit.withArgs('rebound').args[0][1]).to.be.equal(
'Request failed with status code 404',
);
});
});

describe('when some args are wrong', () => {
Expand Down