Skip to content

Commit

Permalink
fix(bodyparser): bubble onFile error when autoProcessing files
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 31, 2019
1 parent 5e96178 commit 8d2bffc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/BodyParser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,18 @@ export class BodyParserMiddleware {
* method.
*/
request.multipart.onFile('*', { deferValidations: true }, async (part, reporter) => {
const tmpPath = this._getTmpPath(multipartConfig)
await streamFile(part, tmpPath, reporter)
return { tmpPath }
/**
* We need to abort the main request when we are unable to process any
* file. Otherwise the error will endup on the file object, which
* is incorrect.
*/
try {
const tmpPath = this._getTmpPath(multipartConfig)
await streamFile(part, tmpPath, reporter)
return { tmpPath }
} catch (error) {
request.multipart.abort(error)
}
})

await request.multipart.process()
Expand Down

0 comments on commit 8d2bffc

Please sign in to comment.