You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have an endpoint that sets a header both when it returns successfully and when it fails with an error. As far as I can tell, currently there is no way to do this easily.
In particular:
Headers are attached to the endpoint’s return value type at type-level, so there is no way to assert that an endpoint sets a header on error.
Headers are attached to the return value at value-level, so there is just no way to set a header when failing.
I tried to come up with some kind of combinator that would do this, but I couldn’t: it all boils down to the fact that combinators are polymorphic over the underlying monad, so there is no way for them to do anything with the error in the error case.
What I was thinking instead is a custom handler monad, that will essentially be ExceptT (headers, ServerError) IO (headers, a) and then hoist it to Handler a by prepending the headers to the error or... and then I’m not sure how to add the headers to the normal response. And, also, this way the headers set will need to be the same for all endpoints, which is not great.
Ultimately, I would be ok with sacrificing 1 and not indicating in the type that a header is set, but 2, together with my previous paragraph, seems to be a big roadblock.
So, I guess, I’m looking for ideas of how this can be achieved and, ideally, eventually upstreamed for the future users.
The text was updated successfully, but these errors were encountered:
With this package one splits error response encoding from the actual handler and the HasServer Throws instance uses ToServantErr to figure out what response headers shall be added for a given error value.
I would like to have an endpoint that sets a header both when it returns successfully and when it fails with an error. As far as I can tell, currently there is no way to do this easily.
In particular:
Headers
are attached to the endpoint’s return value type at type-level, so there is no way to assert that an endpoint sets a header on error.I tried to come up with some kind of combinator that would do this, but I couldn’t: it all boils down to the fact that combinators are polymorphic over the underlying monad, so there is no way for them to do anything with the error in the error case.
What I was thinking instead is a custom handler monad, that will essentially be
ExceptT (headers, ServerError) IO (headers, a)
and then hoist it toHandler a
by prepending the headers to the error or... and then I’m not sure how to add the headers to the normal response. And, also, this way the headers set will need to be the same for all endpoints, which is not great.Ultimately, I would be ok with sacrificing 1 and not indicating in the type that a header is set, but 2, together with my previous paragraph, seems to be a big roadblock.
So, I guess, I’m looking for ideas of how this can be achieved and, ideally, eventually upstreamed for the future users.
The text was updated successfully, but these errors were encountered: