@@ -6,9 +6,29 @@ var util = require('util')
66
77var createError = require ( '..' )
88
9+ var isError = typeof Error . isError === 'function'
10+ ? Error . isError
11+ // eslint-disable-next-line node/no-deprecated-api
12+ : typeof util . isError === 'function'
13+ // eslint-disable-next-line node/no-deprecated-api
14+ ? util . isError
15+ // Fallback for Node.js v23: util.isError was removed in Node.js v23 (EOL), and Error.isError was introduced in Node.js v24
16+ : function ( err ) {
17+ return err instanceof Error
18+ }
19+
20+ var itErrorIsError = typeof Error . isError === 'function'
21+ ? it
22+ : it . skip
23+
24+ // eslint-disable-next-line node/no-deprecated-api
25+ var itUtilIsError = typeof util . isError === 'function'
26+ ? it
27+ : it . skip
28+
929describe ( 'createError(status)' , function ( ) {
1030 it ( 'should create error object' , function ( ) {
11- assert . ok ( util . isError ( createError ( 500 ) ) ) // eslint-disable-line node/no-deprecated-api
31+ assert . ok ( isError ( createError ( 500 ) ) )
1232 } )
1333
1434 describe ( 'Extending Existing Errors with HTTP Properties' , function ( ) {
@@ -126,7 +146,7 @@ describe('createError(status, message)', function () {
126146 } )
127147
128148 it ( 'should create error object' , function ( ) {
129- assert . ok ( util . isError ( this . error ) ) // eslint-disable-line node/no-deprecated-api
149+ assert . ok ( isError ( this . error ) )
130150 } )
131151
132152 it ( 'should have "message" property with message' , function ( ) {
@@ -419,11 +439,17 @@ describe('HTTP Errors', function () {
419439 assert ( ( new createError [ '500' ] ( ) ) instanceof createError . HttpError )
420440 } )
421441
422- it ( 'should support util.isError()' , function ( ) {
442+ itUtilIsError ( 'should support util.isError()' , function ( ) {
423443 /* eslint-disable node/no-deprecated-api */
424444 assert ( util . isError ( createError ( 404 ) ) )
425445 assert ( util . isError ( new createError [ '404' ] ( ) ) )
426446 assert ( util . isError ( new createError [ '500' ] ( ) ) )
427447 /* eslint-enable node/no-deprecated-api */
428448 } )
449+
450+ itErrorIsError ( 'should support Error.isError()' , function ( ) {
451+ assert ( Error . isError ( createError ( 404 ) ) )
452+ assert ( Error . isError ( new createError [ '404' ] ( ) ) )
453+ assert ( Error . isError ( new createError [ '500' ] ( ) ) )
454+ } )
429455} )
0 commit comments