'How to log Celebrate validation errors to the console in Express.js?

I have an Express.js app in which I'm trying to log the validation errors returned by Celebrate to the console so that I can analyze them with the logging service that I use (which is GCP's Cloud Logging).

I'm currently just using the error handling middleware provided by Celebrate as suggested in the documentation:

// app.js

const { errors } = require('celebrate');

...

app.use(errors());

...

How can I extend the middleware (without re-implementing it) so that it also logs the validation errors to the console?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source