Handle when a plugin response fails
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent acd88c3 · Browse files · 3 files·+19 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+19 added−15 removed
- other:+19 added−15 removed
Provenance
- Commit
7550dec- Tree
d6674c4- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
acd88c3
3 files changed+19 added−15 removed
modified:lib/express/plugins/session.js+3 added-2 removed
221 unmodified lines222 * Delegate to store, allowing it to save sessions changes.223 */224 225 response: function(event, callback) {226- exports.Session.store.commit(event.request.session, callback) 227- return true226+ if (event.request.session)227+ return exports.Session.store.commit(event.request.session, callback),228+ true229 }230 }231 })modified:lib/express/core.js+7 added-5 removed
280 unmodified lines281 282 route: function(request, response){ 283 var self = this,284 request = new Request(request, response) 285- request.trigger('request', function(e) {285+ request.trigger('request', function(err) {286 try {287- if (e) throw e287+ if (err) throw err288 if (request.response.finished) return289 if (typeof (body = (new Router(request)).route()) === 'string')290- request.halt(200, body) 291- } catch (e) {292- self.error(e, request)290+ request.halt(200, body, function(err){291+ if (err) self.error(err, request)292+ }) 293+ } catch (err) {294+ self.error(err, request)295 } 296 })297 },298 57 unmodified linesmodified:lib/express/request.js+9 added-8 removed
174 unmodified lines175 176 respond: function(body, encoding, callback) {177 var self = this178 this.response.body = body179- this.trigger('response', function(e) {180- if (e)181- if (callback !== undefined) callback(e)182- else throw e179+ this.trigger('response', function(err) {180+ if (err)181+ if (callback !== undefined) callback(err)182+ else throw err183+ // TODO: use exception handler here184 self.response.writeHeader(self.response.status, self.response.headers)185 self.response.write(self.response.body, encoding)186 self.response.close()186- });187+ })188 },189 190 /**191 * Pass control to the next matching route, or44 unmodified lines236 data.merge({ request: this, response: this.response })237 var self = this,238 complete = 0,239 total = this.plugins.length239- ;(function next(e) {240- if (e || complete === total)241- callback(e)240+ ;(function next(err) {241+ if (err || complete === total)242+ callback(err)243 else {244 if (self.plugins.at(complete++).trigger(new Event(name, data), next) !== true)245 next()246 }33 unmodified lines