Skip to content

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

Open

Description

@LukasRychtecky

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.

Activity

  1. weavejester commented on May 21, 2018

    @weavejester
    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?

  2. added 2 commits that reference this issue on May 21, 2018
    cee1a6d
    05025a6
  3. added a commit that references this issue on Jun 4, 2018
    76a7e98
  4. added 2 commits that reference this issue on Aug 30, 2018
    a029366
    3a95d77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions