Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only add requestFile to tmpUploads if it is not rejected by busboy #171

Merged
merged 7 commits into from
Oct 21, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,16 @@ function fastifyMultipart (fastify, options = {}, done) {
const target = createWriteStream(filepath)
try {
await pump(file.file, target)
this.tmpUploads.push(filepath)
requestFiles.push({ ...file, filepath })
this.tmpUploads.push(filepath)
// busboy set truncated to true when the configured file size limit was reached
if (file.file.truncated) {
const err = new RequestFileTooLargeError()
err.part = file
throw err
}
} catch (err) {
try {
await unlink(filepath)
} catch (err) {
this.log.debug({ err }, 'could not delete file')
}

this.log.error(err)
Copy link
Member

@StarpTech StarpTech Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a bit more context makes it easier to know where it failed.

this.log.error({ err }, 'save request file')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Are the object brackets necessary? I added them just in case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, both should work.

throw err
}
}
Expand Down