twitchtv / twirp

A simple RPC framework with protobuf service definitions
https://twitchtv.github.io/twirp/docs/intro.html
Apache License 2.0
7.2k stars 326 forks source link

RFC 7807 #354

Closed zdufour-asp closed 2 years ago

zdufour-asp commented 2 years ago

Hi, first I just want to say that I really love this framework the more I use it.

I'm really intrigued by IETF's RFC 7807, and I'm thinking about trying to add those fields to some existing twirp endpoints.

The best solution I can find at the moment would be to extend twirp.Error add an Interceptor that tries to err.WithMeta a bunch of times.

That doesn't get me to actually meeting the RFC 7807 spec, since these fields wouldn't be at the top level, but it'd probably be totally fine for now.

I'm curious though -- is there a way to add custom fields to the top level of a twirp error response? It seems like that'd require supporting a Final func(context.Context, string, error) string middleware that receives both the raw bytes of the almost-final response as well as the err returned by the method handler and then returns a potentially modified body.

zdufour-asp commented 2 years ago

Ah, learning lots. I see that I'm just looking for an http middleware (although I'm not sure if this is still actually a good idea)