You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The inheritance of that error causes issues with stack traces and instance logic in JS
Snippet
From the following snippet you can see that the ErrorBase is not an instance of the ErrorBase and the stack trace is wrong
import{ErrorBase,NotFound,StatusCode}from"contracts";conste1=newErrorBase(StatusCode.badRequest,"badRequest","Bad request");console.log({e1InstanceOfError: e1instanceofError,e1InstanceOfErrorBase: e1instanceofErrorBase});conste2=newNotFound("notFound","Not found");console.log({e2InstanceOfError: e2instanceofError,e2InstanceOfErrorBase: e2instanceofErrorBase,e2InstanceOfNotFound: e2instanceofNotFound,});functiona(){thrownewNotFound("notFound","Not found");}functionb(){a();}functionc(){b();}try{c();}catch(error){if(errorinstanceofNotFound){console.log("error is NotFound");}if(errorinstanceofErrorBase){console.log("error is ErrorBase");}if(errorinstanceofError){console.log("error is Error");}console.log({error});console.error(error);}
Output:
{ e1InstanceOfError: true, e1InstanceOfErrorBase: false }
{
e2InstanceOfError: true,
e2InstanceOfErrorBase: false,
e2InstanceOfNotFound: false
}
error is Error
{
error: HttpError
at HttpError (/Users/panenco/work/papi/node_modules/routing-controllers/cjs/http-error/HttpError.js:17:22)
at ErrorBase (/Users/panenco/work/papi/src/contracts/errors/errorBase.error.ts:16:5)
at NotFound (/Users/panenco/work/papi/src/contracts/errors/notFound.error.ts:10:5)
at a (/Users/panenco/work/papi/src/test.ts:15:8)
at b (/Users/panenco/work/papi/src/test.ts:19:2)
at c (/Users/panenco/work/papi/src/test.ts:23:2)
at <anonymous> (/Users/panenco/work/papi/src/test.ts:27:2)
at Object.<anonymous> (/Users/panenco/work/papi/src/test.ts:41:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.F (/Users/panenco/Library/pnpm/global/5/.pnpm/@esbuild-kit+cjs-loader@2.4.2/node_modules/@esbuild-kit/cjs-loader/dist/index.js:1:941) {
httpCode: 404,
message: 'Not found',
code: 404,
reason: 'notFound',
payload: undefined
}
}
HttpError
at HttpError (/Users/panenco/work/papi/node_modules/routing-controllers/cjs/http-error/HttpError.js:17:22)
at ErrorBase (/Users/panenco/work/papi/src/contracts/errors/errorBase.error.ts:16:5)
at NotFound (/Users/panenco/work/papi/src/contracts/errors/notFound.error.ts:10:5)
at a (/Users/panenco/work/papi/src/test.ts:15:8)
at b (/Users/panenco/work/papi/src/test.ts:19:2)
at c (/Users/panenco/work/papi/src/test.ts:23:2)
at <anonymous> (/Users/panenco/work/papi/src/test.ts:27:2)
at Object.<anonymous> (/Users/panenco/work/papi/src/test.ts:41:1)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.F (/Users/panenco/Library/pnpm/global/5/.pnpm/@esbuild-kit+cjs-loader@2.4.2/node_modules/@esbuild-kit/cjs-loader/dist/index.js:1:941) {
httpCode: 404,
message: 'Not found',
code: 404,
reason: 'notFound',
payload: undefined
}
Description
Because of the following line in the
HttpErrorin routing-controllersThe inheritance of that error causes issues with stack traces and instance logic in JS
Snippet
From the following snippet you can see that the
ErrorBaseis not an instance of theErrorBaseand the stack trace is wrongOutput: