diff --git a/ring-core/src/ring/middleware/multipart_params.clj b/ring-core/src/ring/middleware/multipart_params.clj index d0ad0c2c..2af454d8 100644 --- a/ring-core/src/ring/middleware/multipart_params.clj +++ b/ring-core/src/ring/middleware/multipart_params.clj @@ -137,8 +137,11 @@ {:multipart-params params} {:params params})))) -(defn default-invalid-filename-handler [request e] - (response/bad-request (.getMessage e))) +(defn default-invalid-filename-handler + ([request exception] + (response/bad-request (.getMessage exception))) + ([request exception respond raise] + (respond (default-invalid-filename-handler request exception)))) (defn wrap-multipart-params "Middleware to parse multipart parameters from a request. Adds the following @@ -173,8 +176,9 @@ :invalid-filename-handler - A function that gets called when the file being uploaded has an invalid name. - The function should expect two parameters: request and an exception of type - InvalidFileNameException. It should return a ring response." + The sync handler should expect two parameters: request and an exception of + type InvalidFileNameException. The async version should expect four: request, + exception, respond and raise." ([handler] (wrap-multipart-params handler {})) ([handler options] @@ -183,14 +187,14 @@ (fn ([request] (let [req-or-ex (try (multipart-params-request request options) - (catch Exception ex ex))] - (if (instance? Throwable req-or-ex) + (catch InvalidFileNameException ex ex))] + (if (instance? InvalidFileNameException req-or-ex) (invalid-filename-handler request req-or-ex) (handler req-or-ex)))) ([request respond raise] (let [req-or-ex (try (multipart-params-request request options) - (catch Exception ex ex))] - (if (instance? Throwable req-or-ex) - (respond (invalid-filename-handler request req-or-ex)) + (catch InvalidFileNameException ex ex))] + (if (instance? InvalidFileNameException req-or-ex) + (invalid-filename-handler request req-or-ex respond raise) (handler req-or-ex respond raise))))))))