HTTP JSON Error Responses in Go
I like simple structured messages using JSON in error responses, similar to Stripe, Uber and many others…
{ "error": { "type": "validation_failed", "message": "Username is a required field" } } In my last story, I wrote about HTTP Logging and in that I mentioned that I have used “chained” middleware using the Adapter pattern from Mat Ryer’s excellent post. You’ll see that below, but also in addition, I’m wrapping my final true app handler (in this case, CreateUser) inside an ErrHandler type — eh.