juxt / yada

A powerful Clojure web library, full HTTP, full async - see https://juxt.pro/yada/index.html
MIT License
735 stars 97 forks source link

machine readable error replies #205

Open nha opened 7 years ago

nha commented 7 years ago

When parameters are invalid, yada returns an error message in the body. Unfortunately the body returned seems to be text/plain by default, even if the request has, say a accept: application/json header.

Example reply:

{:status 400, :headers {"content-length" "62", "content-type" "text/plain;charset=utf-8"}, :body "Malformed body\r\n\r\n{:status 400, :error {:bar disallowed-key}}\n"}

That's too bad - it is that close to be machine readable!

It means that yada/response-for is not as usable/composable as it could be as well - I would love to go towards a more REPL/data-driven webserver.

Update: it seems there is a special case for application/edn, but even there is is not easy to read since there is an #error tag inside the body (maybe https://clojuredocs.org/clojure.core/Throwable-%3Emap could help?).

yada 1.2.9

I haven't checked, but it looks related to this file https://github.com/juxt/yada/blob/f147f052529689503f839343aab9384280f0ce2d/src/yada/body.clj#L254-L278

nha commented 6 years ago

looks similar to https://github.com/juxt/yada/issues/178