I’ve set up a sinatra web service which accepts JSON-formatted POST messages. It performs various validations on the incoming data and if there are any problems it calls halt 400, "You're doing it wrong" or something to that effect, with a bit more detail on exactly what they’re doing wrong.
The error messages (e.g. “You’re doing it wrong”) are sent to the client just fine, but I’d also like to have them logged on the server so I can see where people are having problems with their client implementations. Is there an easy way to do that?
Check out logging and
Exception#backtrace. You may need to do something likeraise RuntimeError(or some other error) then catch the error and send the results oferror.backtraceto your log.