Skip to content

Commit

Permalink
fix: check if file in req.files is undefined
Browse files Browse the repository at this point in the history
Stops Express returning an empty 400 response early on when indexing the file object in a single file upload.
  • Loading branch information
Dakskihedron committed Jul 3, 2024
1 parent f0f2440 commit 9899604
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion templates/api.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function(app: Express, impl: t.{{className name}}Api) {
{{#if (isContentMultipart .)}}
if (req.files && !Array.isArray(req.files)) {
{{#each (fileUploadProperties schema.properties)}}
req.body[{{{stringLiteral name}}}] = req.files[{{{stringLiteral name}}}]{{#unless isArray}}[0]{{/unless}}
req.body[{{{stringLiteral name}}}] = req.files[{{{stringLiteral name}}}] ? req.files[{{{stringLiteral name}}}]{{#unless isArray}}[0]{{/unless}} : undefined
{{/each}}
}
return {{>frag/fromRequest schema prefix='v.'}}('body', req.body)
Expand Down

0 comments on commit 9899604

Please sign in to comment.