Fork me on GitHub

@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


as-response looks like it might be useful


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.


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


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


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: