Skip to main content

Class: ExceptionWatcher

Defined in: watchers/exception.watcher.ts:43

Records an exception and then answers exactly as Nest would have.

It used to write its own response, and the two did not agree. Nest's BaseExceptionFilter recognises the shape the http-errors package throws — { statusCode, message }, which is what body-parser, serve-static and a great many middlewares raise — and answers with the status it carries. This answered 500 to all of them, and put the thrown message in the body where Nest deliberately does not. Measured on one application with the watcher and one without:

without 413 {"statusCode":413,"message":"request entity too large"}
with 500 {"statusCode":500,"message":"request entity too large",
"error":"Internal Server Error"}

A payload-too-large became an internal error, and the internal message of every other unknown failure reached the client. Installing a debugging tool must not change what the application it is watching answers.

So the response is Nest's own, by inheritance rather than by imitation: the next thing Nest changes about it changes here too.

Extends​

  • BaseExceptionFilter

Implements​

  • ExceptionFilter

Constructors​

Constructor​

new ExceptionWatcher(collector, nestlensConfig, httpAdapterHost, applicationConfig): ExceptionWatcher

Defined in: watchers/exception.watcher.ts:46

Parameters​

collector​

CollectorService

nestlensConfig​

NestLensConfig

httpAdapterHost​

HttpAdapterHost

applicationConfig​

ApplicationConfig

Returns​

ExceptionWatcher

Overrides​

BaseExceptionFilter.constructor

Methods​

catch()​

catch(exception, host): void

Defined in: watchers/exception.watcher.ts:64

unknown, not Error: an application can throw a string, a bare object or null, and Nest hands all of them here exactly as they were thrown. The old signature was a promise the runtime does not keep, and reading .name off null under it took the process down.

Parameters​

exception​

unknown

host​

ArgumentsHost

Returns​

void

Implementation of​

ExceptionFilter.catch

Overrides​

BaseExceptionFilter.catch