Skip to content
Myr

Merge branch 'error-handling'

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

authored by visionmedia · committed by visionmedia · parents 906ef02, e92360e · Browse files · 2 files+28 added−30 removed
This commit

State

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

Diff stats

2 files+28 added−30 removed

  • other:+28 added−30 removed

2 files+28 added−30 removed

modified:lib/express/core.js+27 added-28 removed
3 unmodified lines
4/**5 * Module dependencies.6 */78var showExceptions = require('express/pages/show-exceptions'),9 notFound = require('express/pages/not-found'),8var multipart = require('multipart'),10 multipart = require('multipart'),11 utils = require('express/utils'),12 events = require('events'),13 fs = require('fs')14
104 unmodified lines
119 }120 return body121 }122 else if (this.request.accepts('html') && set('helpful 404'))121 this.request.halt(404, require('express/pages/not-found').render(this.request))123 this.request.halt(404, notFound.render(this.request))124 else125 this.request.halt()126 },127
95 unmodified lines
223 request.body = ''224 request.setBodyEncoding('binary')225 var pendingFiles226 225 function callback(e, result) { 226 if (e)227 self.error(e, request, response)227 function callback(err, result) { 228 if (err)229 Express.error(err, request, response)230 else if (!pendingFiles)231 self.route(request, response)232 }233 if (request.headers['content-type'] &&
55 unmodified lines
289 if (err) throw err290 if (request.response.finished) return291 if (typeof (body = (new Router(request)).route()) === 'string')292 request.halt(200, body, null, function(err){291 if (err) self.error(err, request)293 if (err) Express.error(err, request, response)294 }) 295 } catch (err) {294 self.error(err, request)296 Express.error(err, request, response)297 } 298 })297 },298 299 /**300 * Handle errors.301 *302 * @param {Error} e303 * @param {object} request304 * @param {object} response305 * @api private306 */307 308 error: function (e, request, response) {309 if (!(request instanceof Request))310 request = new Request(request, response),311 request.trigger('request')312 if (request.accepts('html') && set('show exceptions'))313 request.halt(500, require('express/pages/show-exceptions').render(request, e))314 else315 request.halt(500)316 if (set('throw exceptions'))317 throw e299 }300})301302// --- Express
7 unmodified lines
310 params: {},311 server: new Server312}313314/**315 * Handle the given _err_ in relation to _request_ and _response_.316 *317 * @param {Error} err318 * @param {object} request319 * @param {object} response320 * @api private321 */322 323Express.error = function (err, request, response) {324 if (request.accepts('html') && set('show exceptions'))325 request.halt(500, showExceptions.render(request, err))326 else327 request.halt(500)328 if (set('throw exceptions'))329 throw err330}331332// --- Defaults333334configure(function(){335 use(require('express/plugins/view').View)
19 unmodified lines
modified:lib/express/request.js+1 added-2 removed
177 unmodified lines
178 this.response.body = body179 this.trigger('response', function(err) {180 if (err)181 if (callback !== undefined) callback(err)182 else throw err183 // TODO: use exception handler here182 else Express.error(err, self, self.response)183 self.response.writeHeader(self.response.status, self.response.headers)184 self.response.write(self.response.body, encoding)185 self.response.close()186 }, true)
97 unmodified lines