UNPKG

@nestjs/core

Version:

The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.

23 lines (22 loc) • 714 B
/** * Creates an error without capturing a stack trace, for exceptions Nest throws * itself where the stack would only hold framework frames (e.g. the 404 for an * unknown route). Capturing it is most of what creating the error costs. * * Leaves `Error.stackTraceLimit` alone when it is read-only, since assigning * it would throw. */ export function withoutStackTrace(create) { const descriptor = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit'); if (!descriptor?.writable) { return create(); } const { stackTraceLimit } = Error; Error.stackTraceLimit = 0; try { return create(); } finally { Error.stackTraceLimit = stackTraceLimit; } }