Fork me on GitHub
#liberator
<
2015-10-14
>
rickmoynihan11:10:39

@jonas: Just signed in here to ask a similar question.... I'd basically like to find a way to return structured JSON error objects from all the handlers if the accept header is JSON... Would be nice to also content-neg them for json/edn and HTML. Some specific paths will generate specific errors e.g. a 422 might return a JSON error map saying which form fields had errors... but I'd also like to upcast all the other errors to be JSON objects... e.g. instead of just returning a 410 "Resource Gone" I'd like to convert that error to something like: {'error-message': "Resource Gone"} if JSON is requested

rickmoynihan11:10:58

as-response looks like it might be useful

ordnungswidrig17:10:37

This is a know problem in liberator right now, there’s no media-type in the context for handlers before content negotitaion. I will post a work around later, unfortunately I need to pop out for an appointment now.

jonas17:10:31

@ordnungswidrig: Thanks, I’m looking forward to the workaround.

jonas17:10:56

@rickmoynihan: I will take a look at as-response. Thanks for the pointer

ordnungswidrig21:10:47

Basically what I’m using is a function for :as-response that adds a fallback media type to the context and passes on to the default as-reponse method: