Skip to content
Myr

Merge branch 'errors'

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

authored by visionmedia · committed by visionmedia · parents ab6ad94, ff1250c · Browse files · 2 files+54 added−29 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+54 added−29 removed

  • other:+54 added−29 removed

2 files+54 added−29 removed

modified:lib/express/core.js+5 added-27 removed
3 unmodified lines
4/**5 * Module dependencies.6 */78var showExceptions = require('express/pages/show-exceptions'),9 notFound = require('express/pages/not-found'),10 multipart = require('multipart'),8var multipart = require('multipart'),9 utils = require('express/utils'),10 events = require('events'),11 fs = require('fs')12
103 unmodified lines
116 return this.route()117 }118 return body119 }122 else if (this.request.accepts('html') && set('helpful 404'))123 this.request.halt(404, notFound.render(this.request))120 else125 this.request.halt()121 this.request.notFound()122 },123 124 /**125 * Attempt to match a route from Express.routes.
95 unmodified lines
221 function callback(err) {222 if (!(request instanceof Request))223 request = new Request(request, response)224 if (err)229 Express.error(err, request, response)225 request.error(err)226 else if (!pendingFiles)227 self.route(request, response)228 }229 if (request.headers['content-type'] &&
56 unmodified lines
286 if (err) throw err287 if (request.response.finished) return288 if (typeof (body = (new Router(request)).route()) === 'string')289 request.halt(200, body, function(err){294 if (err) Express.error(err, request, response)290 if (err) request.error(err)291 }) 292 } catch (err) {297 Express.error(err, request, response)293 request.error(err)294 } 295 })296 }297})
9 unmodified lines
307 params: {},308 server: new Server309}310315/**316 * Handle the given _err_ in relation to _request_ and _response_.317 *318 * @param {Error} err319 * @param {object} request320 * @param {object} response321 * @api private322 */323 324Express.error = function (err, request, response) {325 if (request.accepts('html') && set('show exceptions'))326 request.halt(500, showExceptions.render(request, err))327 else328 request.halt(500)329 if (set('throw exceptions'))330 throw err331}332311// --- Defaults312313configure(function(){314 use(require('express/plugins/view').View)
19 unmodified lines
modified:lib/express/request.js+49 added-2 removed
3 unmodified lines
4/**5 * Module dependencies.6 */78var showExceptions = require('express/pages/show-exceptions'),9 notFound = require('express/pages/not-found'),8var statusBodies = require('http').STATUS_CODES,10 statusBodies = require('http').STATUS_CODES,11 queryString = require('querystring'),12 mime = require('express/mime'),13 url = require('url')14
173 unmodified lines
188 this.response.body = body189 this.trigger('response', function(err) {190 if (err)191 if (callback !== undefined) callback(err)190 else Express.error(err, self, self.response)192 else self.error(err)193 self.response.writeHeader(self.response.status, self.response.headers)194 self.response.write(self.response.body, encoding)195 self.response.close()196 }, true)
91 unmodified lines
288 this.header('content-disposition', path289 ? 'attachment; filename="' + path + '"'290 : 'attachment')291 return this292 },293 294 /**295 * Handle exceptions.296 *297 * When "html" is accepted, and "show exceptions" is enabled298 * the show-exceptions page will be shown. Otherwise299 * the request will halt with default 500 status body.300 *301 * When "throw exceptions" is enabled the error will be302 * re-thrown, terminating the process (unless otherwise caught).303 *304 * @param {Error} err305 * @return {Request}306 * @settings 'throw exceptions', 'show exceptions'307 * @api public308 */309 310 error: function(err) {311 if (this.accepts('html') && set('show exceptions'))312 this.halt(500, showExceptions.render(this, err))313 else314 this.halt(500)315 if (set('throw exceptions'))316 throw err317 return this318 },319 320 /**321 * Halt with 404 Not Found.322 *323 * When "html" is accepted, and "helpful 404" is enabled324 * the not-found page will be shown, otherwise the 325 * request will halt with default 404 status body.326 *327 * @return {Request}328 * @api public329 */330 331 notFound: function() {332 if (this.accepts('html') && set('helpful 404'))333 this.halt(404, notFound.render(this))334 else335 this.halt()336 return this337 }338})