Removed Express.error(), Added public Request#error()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent ab6ad94 · Browse files · 2 files·+31 added−23 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+31 added−23 removed
- other:+31 added−23 removed
Provenance
- Commit
4297c10- Tree
7c8467a- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
ab6ad94
2 files changed+31 added−23 removed
modified:lib/express/core.js+3 added-21 removed
224 unmodified lines225 function callback(err) {226 if (!(request instanceof Request))227 request = new Request(request, response)228 if (err)229- Express.error(err, request, response)229+ request.error(err)230 else if (!pendingFiles)231 self.route(request, response)232 }233 if (request.headers['content-type'] &&56 unmodified lines290 if (err) throw err291 if (request.response.finished) return292 if (typeof (body = (new Router(request)).route()) === 'string')293 request.halt(200, body, function(err){294- if (err) Express.error(err, request, response)294+ if (err) request.error(err)295 }) 296 } catch (err) {297- Express.error(err, request, response)297+ request.error(err)298 } 299 })300 }301 })9 unmodified lines311 params: {},312 server: new Server313 }314 315-/**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- 324-Express.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-}332-315 // --- Defaults316 317 configure(function(){318 use(require('express/plugins/view').View)19 unmodified linesmodified:lib/express/request.js+28 added-2 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8+var showExceptions = require('express/pages/show-exceptions'),8-var statusBodies = require('http').STATUS_CODES,9+ statusBodies = require('http').STATUS_CODES,10 queryString = require('querystring'),11 mime = require('express/mime'),12 url = require('url')13 173 unmodified lines187 this.response.body = body188 this.trigger('response', function(err) {189 if (err)190 if (callback !== undefined) callback(err)190- else Express.error(err, self, self.response)191+ else self.error(err)192 self.response.writeHeader(self.response.status, self.response.headers)193 self.response.write(self.response.body, encoding)194 self.response.close()195 }, true)91 unmodified lines287 this.header('content-disposition', path288 ? 'attachment; filename="' + path + '"'289 : 'attachment')290 return this291+ },292+ 293+ /**294+ * Handle exceptions.295+ *296+ * When "html" is accepted, and "show exceptions" is enabled297+ * the show-exceptions page will be shown. Otherwise298+ * the request will halt with default 500 status body.299+ *300+ * When "throw exceptions" is enabled the error will be301+ * re-thrown, terminating the process (unless otherwise caught).302+ *303+ * @param {Error} err304+ * @return {Request}305+ * @api public306+ */307+ 308+ error: function(err) {309+ if (this.accepts('html') && set('show exceptions'))310+ this.halt(500, showExceptions.render(this, err))311+ else312+ this.halt(500)313+ if (set('throw exceptions'))314+ throw err315+ return this316 }317 })