Skip to content

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

Open
@LukasRychtecky

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.

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