Closed LukasRychtecky closed 6 years ago
Thanks for the bug report! My thought is that we should have two static error handlers - one which would be a last resort and show plaintext, JSON, or some other fallback. The second "normal" error handler we put before Muuntaja's formatting.
In this way, we display a correctly formatted error message when something goes wrong with the application itself, and we have a fallback error message in case something goes wrong with Muuntaja's formatting.
Thanks for quick response.
If I understand it correctly I should add new middleware that will be called at the end of a chain of middlewares, checks for response's body type? It'd be helpful if you can describe it more deeply and I will try to fix it.
So my thought is something like:
:duct.handler.static/internal-server-error
{:body {:error :internal-server-error}}
:duct.handler.static/uncaught-server-error
{:body "Uncaught error!"}
:duct.core.handler
{:middleware [#ig/ref :duct.middleware.web/hide-internal-errors
#ig/ref :duct.middleware.web/format
#ig/ref :duct.middleware.web/hide-uncaught-errors]}
However, I'll need to think of the best way to implement it in practice. I am currently working on Duct, so I should get to fixing this error fairly soon.
Fine, so will you take care of this or should I? I temporary fixed the issue in my services by defining
:duct.handler.static/internal-server-error
{:body "{\"error\":\"internal-server-error\"}"}
I can take care of it, but it might take a week or so for me to get around to it.
I've looked into this, and after some experimentation, I think I'm going to go with a default JSON response for now, as that's by far the simplest option. It would be nice if the 500 error had content type handling, but realistically any client is going to see the 500 status code and just report an error.
Hi,
when an exception is raised (in a Ring handler) it's caught by
wrap-hide-errors
middleware. Unfortunatelyrequest
inwrap-hide-errors
has no:muuntaja/response
nor:muuntaja/request
attributes and a static response:duct.handler.static/internal-server-error
is not marshalled to a string, thus Ring raises an exceptionNo implementation of method: :write-body-to-stream of protocol: #'ring.core.protocols/StreamableResponseBody found for class: clojure.lang.PersistentArrayMap
.I've tried on
0.6.4
version (because of my existing services and it's still default in lein template).I have got a couple of solutions on my mind:
{:status 500, :body "{\"error\":\"internal-server-error\"}"}
What do you think?