refactor res.status=

This commit is contained in:
TJ Holowaychuk 2014-06-10 14:33:13 -07:00
parent ed8beb7d79
commit 696d55d73b

View file

@ -10,10 +10,10 @@ var escape = require('escape-html');
var onfinish = require('finished'); var onfinish = require('finished');
var status = require('statuses'); var status = require('statuses');
var destroy = require('dethroy'); var destroy = require('dethroy');
var assert = require('assert');
var http = require('http'); var http = require('http');
var path = require('path'); var path = require('path');
var vary = require('vary'); var vary = require('vary');
var assert = require('assert');
var basename = path.basename; var basename = path.basename;
var extname = path.extname; var extname = path.extname;
@ -66,12 +66,10 @@ module.exports = {
*/ */
set status(code) { set status(code) {
assert(typeof code === 'number', 'status code must be a number'); assert('number' == typeof code, 'status code must be a number');
if(!http.STATUS_CODES[code]) throw new Error('invalid status code: ' + code); assert(http.STATUS_CODES[code], 'invalid status code: ' + code);
this._explicitStatus = true; this._explicitStatus = true;
this.res.statusCode = code; this.res.statusCode = code;
if (this.body && status.empty[code]) this.body = null; if (this.body && status.empty[code]) this.body = null;
}, },