Skip to content

Commit fd3b405

Browse files
committed
Deprecate combined status, response signatures
closes expressjs#2227
1 parent 21bb2ef commit fd3b405

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

History.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ unreleased
66
- `app.set('query parser', 'simple')` parse with "querystring" core module
77
- `app.set('query parser', false)` disable query string parsing
88
- `app.set('query parser', true)` enable simple parsing
9+
* deprecate `res.json(status, obj)` -- use `res.status(status).json(obj)` instead
10+
* deprecate `res.jsonp(status, obj)` -- use `res.status(status).jsonp(obj)` instead
11+
* deprecate `res.send(status, body)` -- use `res.status(status).send(body)` instead
912
1013
1114
- Respond after request fully read

lib/response.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ res.links = function(links){
7272
* res.send(new Buffer('wahoo'));
7373
* res.send({ some: 'json' });
7474
* res.send('<p>some html</p>');
75-
* res.send(404, 'Sorry, cant find that');
76-
* res.send(404);
7775
*
76+
* @param {string|number|boolean|object|Buffer} body
7877
* @api public
7978
*/
8079

@@ -92,9 +91,10 @@ res.send = function send(body) {
9291
if (arguments.length === 2) {
9392
// res.send(body, status) backwards compat
9493
if (typeof arguments[0] !== 'number' && typeof arguments[1] === 'number') {
95-
deprecate('res.send(body, status): Use res.send(status, body) instead');
94+
deprecate('res.send(body, status): Use res.status(status).send(body) instead');
9695
this.statusCode = arguments[1];
9796
} else {
97+
deprecate('res.send(status, body): Use res.status(status).send(body) instead');
9898
this.statusCode = arguments[0];
9999
chunk = arguments[1];
100100
}
@@ -107,6 +107,7 @@ res.send = function send(body) {
107107
this.type('txt');
108108
}
109109

110+
deprecate('res.send(status): Use res.status(status).end() instead');
110111
this.statusCode = chunk;
111112
chunk = http.STATUS_CODES[chunk];
112113
}
@@ -197,9 +198,8 @@ res.send = function send(body) {
197198
*
198199
* res.json(null);
199200
* res.json({ user: 'tj' });
200-
* res.json(500, 'oh noes!');
201-
* res.json(404, 'I dont have that');
202201
*
202+
* @param {string|number|boolean|object} obj
203203
* @api public
204204
*/
205205

@@ -210,13 +210,10 @@ res.json = function json(obj) {
210210
if (arguments.length === 2) {
211211
// res.json(body, status) backwards compat
212212
if (typeof arguments[1] === 'number') {
213+
deprecate('res.json(obj, status): Use res.status(status).json(obj) instead');
213214
this.statusCode = arguments[1];
214-
if (typeof arguments[0] === 'number') {
215-
deprecate('res.json(obj, status): Use res.json(status, obj) instead');
216-
} else {
217-
deprecate('res.json(num, status): Use res.status(status).json(num) instead');
218-
}
219215
} else {
216+
deprecate('res.json(status, obj): Use res.status(status).json(obj) instead');
220217
this.statusCode = arguments[0];
221218
val = arguments[1];
222219
}
@@ -243,9 +240,8 @@ res.json = function json(obj) {
243240
*
244241
* res.jsonp(null);
245242
* res.jsonp({ user: 'tj' });
246-
* res.jsonp(500, 'oh noes!');
247-
* res.jsonp(404, 'I dont have that');
248243
*
244+
* @param {string|number|boolean|object} obj
249245
* @api public
250246
*/
251247

@@ -256,13 +252,10 @@ res.jsonp = function jsonp(obj) {
256252
if (arguments.length === 2) {
257253
// res.json(body, status) backwards compat
258254
if (typeof arguments[1] === 'number') {
255+
deprecate('res.jsonp(obj, status): Use res.status(status).json(obj) instead');
259256
this.statusCode = arguments[1];
260-
if (typeof arguments[0] === 'number') {
261-
deprecate('res.jsonp(obj, status): Use res.jsonp(status, obj) instead');
262-
} else {
263-
deprecate('res.jsonp(num, status): Use res.status(status).jsonp(num) instead');
264-
}
265257
} else {
258+
deprecate('res.jsonp(status, obj): Use res.status(status).jsonp(obj) instead');
266259
this.statusCode = arguments[0];
267260
val = arguments[1];
268261
}

0 commit comments

Comments
 (0)