Skip to content
Myr

Throwing InvalidResponseBody exception when responding without a body

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

authored by visionmedia · committed by visionmedia · parent b6ec009 · Browse files · 4 files+26 added−4 removed
This commit

State

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

Diff stats

4 files+26 added−4 removed

  • tests:+9 added−0 removed
  • other:+17 added−4 removed

4 files+26 added−4 removed

modified:lib/express/core.js+4 added-4 removed
144 unmodified lines
145 matchingRoute: function(){146 for (var i = 0, len = Express.routes.length; i < len; ++i)147 if (this.match(Express.routes[i]))148 return Express.routes[i]149 throw new NotFoundError(this.request)149 notFound()150 },151 152 /**153 * Check if _route_ matches the current request.
96 unmodified lines
250 * @api private251 */252 253 respond: function(body){254 // TODO: halt(404) unless a response body and status are set 254 if (body) this.response.body = body255 if (typeof this.response.body != 'string') throw new InvalidResponseBody(this.request)256 this.response.sendHeader(this.response.status || 404, this.response.headers)257 this.response.sendBody(this.response.body || '')256 this.response.sendHeader(this.response.status, this.response.headers)257 this.response.sendBody(this.response.body)258 this.response.finish()259 }260})261
10 unmodified lines
modified:lib/express/exceptions.js+9 added
modified:lib/express/helpers.js+4 added
156 unmodified lines
157 return Express.server.respond(body)158 throw new InvalidStatusCode(code)159}160161exports.notFound = function() {162 throw new NotFoundError(Express.server.request)163}164165/**166 * Escape special characters in _html_.167 *168 * @param {string} html
86 unmodified lines
modified:spec/spec.core.routing.js+9 added