Closed neongrau closed 3 weeks ago
Hi. I think it makes sense to add more details to exceptions.
I think it would be best to add ResponseInvalidError#errors
or ResponseInvalidError#failure.errors
to return an array of error objects (Schema::ValidationError
) coming from the schema validation result and use that to get detailed information about what went wrong during validation without leaking too many details of your actual response body.
Making the actual response available on the exception makes sense to me as well for debugging, but I would not use that to log the response body.
By the way, if you use request.validate_response(rack_response)
without passing raise_error: true
you get an object where you can get all details including the response body. Somehing like:
response = Rack::Response[*app.call(env)]
request = Rack::Request.new(env)
validated = definition.validate_response(request, response)
unless validated.valid?
validated.body # => parsed response body
validated.error # => Failure instance
validated.error.errors.map(&:message)
end
By the way, if you use
request.validate_response(rack_response)
without passingraise_error: true
you get an object where you can get all details including the response body. Somehing like:
Thanks! That seems to work nice.
Logging at this point is just because some minor errors (mostly missing null being allowed) are still too abundant.
Once i got the bulk going without errors i will switch over to send validation problems to Sentry and later have request and response validation active all the time on our public development server (opposed to just on my local dev machine).
When i get errors about this and that field not being of the right type. I really need to see what the response actually was.
Trying to write a log file with the actual response (prettified json) and the error so i can later review those instead of having it break with me wondering what was wrong.
So best would be to have the full result of @app.call(env) in the error object so i can log away and just pass on the result to see.
Would this currently be possible?