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 33
44 * Drop support for Node.js 0.6
55 * Remove ` I'mateapot ` export; use ` ImATeapot ` instead
6+ * Remove support for status being non-first argument
67 * Rename ` UnorderedCollection ` constructor to ` TooEarly `
78 * deps: depd@2.0.0
89 - Replace internal ` eval ` usage with ` Function ` constructor
Original file line number Diff line number Diff line change @@ -54,24 +54,18 @@ function createError () {
5454 var props = { }
5555 for ( var i = 0 ; i < arguments . length ; i ++ ) {
5656 var arg = arguments [ i ]
57- if ( arg instanceof Error ) {
57+ var type = typeof arg
58+ if ( type === 'object' && arg instanceof Error ) {
5859 err = arg
5960 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 )
7569 }
7670 }
7771
Original file line number Diff line number Diff line change @@ -226,11 +226,9 @@ describe('HTTP Errors', function () {
226226 } )
227227
228228 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 / )
234232 } )
235233
236234 it ( 'createError(msg)' , function ( ) {
You can’t perform that action at this time.
0 commit comments