rgov
rgov

Reputation: 4329

Logging Hapi validation errors automatically

I run a third-party application that uses Joi for validating outbound API responses.

A certain API call was returning a very generic 500 Internal Server Error with no error description in the API response nor output to the console.

I spent a while stepping through very circuitous package internals to finally find the ValidationError message that described what part of the output did not match the spec.

According to the Hapi docs, the default validation options use failAction: 'error' which is defined as send an Internal Server Error (500) response.

I think it's reasonable for a production server to return a sanitized 500 status code to the user agent, but I need to be able to diagnose the problem from the server side.

I could override the failAction for each route but that is an invasive change to third-party code. What other options do I have for logging globally?

Upvotes: 1

Views: 800

Answers (1)

rgov
rgov

Reputation: 4329

I ended up enabling hapi-pino which seemed to work out of the box.

Upvotes: 1

Related Questions