Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught exception when a request body is not valid e.g. JSON #8

Open
LukasRychtecky opened this issue May 19, 2018 · 2 comments
Open

Comments

@LukasRychtecky
Copy link

Hi,

I found that a usage of muuntaja.middleware/wrap-format is used in duct.middleware.web/format component without wrapping it into muuntaja.middleware/wrap-exception thus when a request body contains invalid JSON an exception is raised and couldn't be caught.

Quick and dirty fix could be like this:

(defmethod ig/init-key ::format [_ options]
  (fn [a]
    (mm/wrap-exception
      (mm/wrap-format a (deep-merge mc/default-options options))
      (fn [ex fmt request]
         {:status 400
          :headers {"Content-Type" "text/plain"}
          :body (str "Malformed " format " request.")}))))

But I think the best would be to allow a developer to define its own handler via options.
What do you think?

Thanks for feedback.

@weavejester
Copy link
Contributor

I think this is a good idea, though as you mention, the best way forward would be to allow developers to define their own handler through an option.

Do we know that an exception will only be raised if the content is malformed?

@LukasRychtecky
Copy link
Author

It's recommended by Muuntaja https://github.com/metosin/muuntaja/blob/8e59542c5e557467de2d0018610c0d0a38d01e87/src/clj/muuntaja/middleware.clj#L17 (it checks for a type of an exception).

LukasRychtecky added a commit to LukasRychtecky/module.web that referenced this issue May 21, 2018
LukasRychtecky added a commit to LukasRychtecky/module.web that referenced this issue May 25, 2018
LukasRychtecky added a commit to LukasRychtecky/module.web that referenced this issue Jun 4, 2018
LukasRychtecky added a commit to LukasRychtecky/module.web that referenced this issue Aug 30, 2018
LukasRychtecky added a commit to LukasRychtecky/module.web that referenced this issue Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants