Skip to content

Commit

Permalink
add options to customize time error message
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrmatos committed Mar 4, 2019
1 parent 805254a commit 8d5da92
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/in-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ScriptsManager.prototype.execute = function (inputs, options, cb) {

var timeout = setTimeout(function () {
resolved = true
cb(new Error('Timeout error during executing script'))
cb(new Error(options.timeoutErrorMessage || 'Timeout error during executing script'))
}, options.timeout || this.options.timeout)

timeout.unref()
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ScriptsManager.prototype.execute = function (inputs, options, cb) {
var timeout = setTimeout(function () {
worker.kill()
killed = true
cb(new Error('Timeout error during executing script'))
cb(new Error(options.timeoutErrorMessage || 'Timeout error during executing script'))
}, options.timeout || this.options.timeout)

timeout.unref()
Expand Down
2 changes: 1 addition & 1 deletion lib/manager-servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ScriptsManager.prototype.start = function (cb) {

var error = new Error()
error.weak = true
error.message = 'Timeout error during executing script'
error.message = reqOptions.timeoutErrorMessage || 'Timeout error during executing script'

self._runningRequests = self._runningRequests.filter(r => r.rid !== reqOptions.rid)

Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,17 @@ describe('scripts manager', function () {
})
})

it('should be able to customize message when timeout error', function (done) {
scriptsManager.execute({ foo: 'foo' }, {
execModulePath: path.join(__dirname, 'scripts', 'timeout.js'),
timeout: 10,
timeoutErrorMessage: 'Timeout testing case'
}, function (err) {
err.message.should.be.eql('Timeout testing case')
done()
})
})

it('should not call callback after timeout error', function (done) {
var resolved = 0

Expand Down

0 comments on commit 8d5da92

Please sign in to comment.