File tree Expand file tree Collapse file tree 3 files changed +14
-21
lines changed Expand file tree Collapse file tree 3 files changed +14
-21
lines changed Original file line number Diff line number Diff line change 3
3
4
4
* Drop support for Node.js 0.6
5
5
* Remove ` I'mateapot ` export; use ` ImATeapot ` instead
6
+ * Remove support for status being non-first argument
6
7
* Rename ` UnorderedCollection ` constructor to ` TooEarly `
7
8
* deps: depd@2.0.0
8
9
- Replace internal ` eval ` usage with ` Function ` constructor
Original file line number Diff line number Diff line change @@ -54,24 +54,18 @@ function createError () {
54
54
var props = { }
55
55
for ( var i = 0 ; i < arguments . length ; i ++ ) {
56
56
var arg = arguments [ i ]
57
- if ( arg instanceof Error ) {
57
+ var type = typeof arg
58
+ if ( type === 'object' && arg instanceof Error ) {
58
59
err = arg
59
60
status = err . status || err . statusCode || status
60
- continue
61
- }
62
- switch ( typeof arg ) {
63
- case 'string' :
64
- msg = arg
65
- break
66
- case 'number' :
67
- status = arg
68
- if ( i !== 0 ) {
69
- deprecate ( 'non-first-argument status code; replace with createError(' + arg + ', ...)' )
70
- }
71
- break
72
- case 'object' :
73
- props = arg
74
- break
61
+ } else if ( type === 'number' && i === 0 ) {
62
+ status = arg
63
+ } else if ( type === 'string' ) {
64
+ msg = arg
65
+ } else if ( type === 'object' ) {
66
+ props = arg
67
+ } else {
68
+ throw new TypeError ( 'argument #' + ( i + 1 ) + ' unsupported type ' + type )
75
69
}
76
70
}
77
71
Original file line number Diff line number Diff line change @@ -226,11 +226,9 @@ describe('HTTP Errors', function () {
226
226
} )
227
227
228
228
it ( 'createError(msg, status)' , function ( ) {
229
- var err = createError ( 'LOL' , 404 )
230
- assert . strictEqual ( err . name , 'NotFoundError' )
231
- assert . strictEqual ( err . message , 'LOL' )
232
- assert . strictEqual ( err . status , 404 )
233
- assert . strictEqual ( err . statusCode , 404 )
229
+ assert . throws ( function ( ) {
230
+ createError ( 'LOL' , 404 )
231
+ } , / a r g u m e n t # 2 u n s u p p o r t e d t y p e n u m b e r / )
234
232
} )
235
233
236
234
it ( 'createError(msg)' , function ( ) {
You can’t perform that action at this time.
0 commit comments