|
137 | 137 | {:multipart-params params} |
138 | 138 | {:params params})))) |
139 | 139 |
|
140 | | -(defn default-invalid-filename-handler [request e] |
141 | | - (response/bad-request (.getMessage e))) |
| 140 | +(defn default-invalid-filename-handler |
| 141 | + ([request exception] |
| 142 | + (response/bad-request (.getMessage exception))) |
| 143 | + ([request exception respond raise] |
| 144 | + (respond (default-invalid-filename-handler request exception)))) |
142 | 145 |
|
143 | 146 | (defn wrap-multipart-params |
144 | 147 | "Middleware to parse multipart parameters from a request. Adds the following |
|
173 | 176 |
|
174 | 177 | :invalid-filename-handler |
175 | 178 | - A function that gets called when the file being uploaded has an invalid name. |
176 | | - The function should expect two parameters: request and an exception of type |
177 | | - InvalidFileNameException. It should return a ring response." |
| 179 | + The sync handler should expect two parameters: request and an exception of |
| 180 | + type InvalidFileNameException. The async version should expect four: request, |
| 181 | + exception, respond and raise." |
178 | 182 | ([handler] |
179 | 183 | (wrap-multipart-params handler {})) |
180 | 184 | ([handler options] |
|
183 | 187 | (fn ([request] |
184 | 188 | (let [req-or-ex (try |
185 | 189 | (multipart-params-request request options) |
186 | | - (catch Exception ex ex))] |
187 | | - (if (instance? Throwable req-or-ex) |
| 190 | + (catch InvalidFileNameException ex ex))] |
| 191 | + (if (instance? InvalidFileNameException req-or-ex) |
188 | 192 | (invalid-filename-handler request req-or-ex) |
189 | 193 | (handler req-or-ex)))) |
190 | 194 | ([request respond raise] |
191 | 195 | (let [req-or-ex (try |
192 | 196 | (multipart-params-request request options) |
193 | | - (catch Exception ex ex))] |
194 | | - (if (instance? Throwable req-or-ex) |
195 | | - (respond (invalid-filename-handler request req-or-ex)) |
| 197 | + (catch InvalidFileNameException ex ex))] |
| 198 | + (if (instance? InvalidFileNameException req-or-ex) |
| 199 | + (invalid-filename-handler request req-or-ex respond raise) |
196 | 200 | (handler req-or-ex respond raise)))))))) |
0 commit comments