Create an API via NestJS Part III

Create Extended Error handler

  1. Create folder:
    mkdir src/shared && cd src/shared
  2. Create the filter:
    touch http-error.filter.ts
  3. Write simple error handler

Include custom error handler as a provider to the app module


Add a logger to this error handler

The next thing that we should do is creating the Logger for our ErrorHandler:

Open your http-error.filter.ts file and type simple logger:

Pay attention, this code must be member of catch() function

Now if we send some incorrect request we should see:

console output

Looks pretty good, but we still don't logging crrect requests.

Let's make interceptor

Create a new file: touch src/shared/logging.interceptor.ts

And write simple logger:


Now we can connect it as a provider to app.module


Check how it works. Start the server and send some correct request, you should get some like this: