Create an API via NestJS
November 24, 2019
Create an API via NestJS Part III
Create Extended Error handler
- Create folder:
mkdir src/shared && cd src/shared
- Create the filter:
touch http-error.filter.ts
- 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:
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: