From 98996045430b68bac05545e498d1999244c84f29 Mon Sep 17 00:00:00 2001 From: Nathan Zhou Date: Wed, 3 Jul 2024 12:09:42 +1200 Subject: [PATCH] fix: check if file in req.files is undefined Stops Express returning an empty 400 response early on when indexing the file object in a single file upload. --- templates/api.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/api.hbs b/templates/api.hbs index 937524e..8a0308e 100644 --- a/templates/api.hbs +++ b/templates/api.hbs @@ -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)