Skip to content
Myr

Request#error() now accepts a callback function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

A common idiom is / will be to accept a callback function in most cases so this will help to keep things DRY

authored by visionmedia · committed by visionmedia · parent 1e44081 · Browse files · 1 file+12 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−10 removed

  • other:+12 added−10 removed

1 file+12 added−10 removed

modified:lib/express/request.js+12 added-10 removed
190 unmodified lines
191 respond: function(body, encoding, callback) {192 var self = this193 this.response.body = body194 this.trigger('response', function(err) {195 if (err)196 if (callback !== undefined) callback(err)197 else self.error(err)195 if (err) self.error(err, callback)196 // TODO: revisit. when this is true node will add Transfer-Encoding: chunked197 // along with a response body, which is not ideal when the user attemps198 // to respond with no body199 if (!body) self.response.useChunkedEncodingByDefault = false
17 unmodified lines
217 first = true218 stream219 .addListener('error', function(err){220 if (first)223 return self.error(err)221 return self.error(err, callback)222 self.response.end()223 if (callback !== undefined) callback(err)224 })225 .addListener('data', function(data){
7 unmodified lines
233 self.response.write(data, 'binary')234 })235 .addListener('end', function(){236 self.trigger('response', function(err){239 if (err) {240 stream.destroy()241 if (callback !== undefined) callback(err)242 else self.error(err)243 }237 if (err)238 stream.destroy(),239 self.error(err, callback)240 self.response.end()241 }, true)242 })243 },
109 unmodified lines
353 *354 * When "throw exceptions" is enabled the error will be355 * re-thrown, terminating the process (unless otherwise caught).356 *357 * Also a _callback_ function may be supplied, which when defined358 * will be called, by-passing the process mentioned above.359 *360 * @param {Error} err361 * @param {function} callback362 * @return {Request}363 * @settings 'throw exceptions', 'show exceptions'364 * @api public365 */366 367 error: function(err) {367 error: function(err, callback) {368 if (callback)369 return callback(err)370 if (Express.error)371 Express.error.call(this, err)372 else if (this.accepts('html') && set('show exceptions'))373 this.halt(500, showExceptions.render(this, err))
36 unmodified lines