Skip to content

Conversation

@fenos
Copy link
Collaborator

@fenos fenos commented Jan 17, 2024

This small PR simply allows error propagation in the namingFunction.

Currently, if an error is thrown from the namingFunction the error is swallowed and a 500 error code is returned.
This behavior is not ideal, in my use case I rely on the metadata in order to create a valid uploadID.

For this reason the metadata is validated in the naming function. If some of the fields don't pass the validation instead of returning a 400 status code, the application returns a non-ideal 500

@fenos fenos force-pushed the fix/propagate-error-on-create-hook branch from 716dbaa to 3f7fd83 Compare January 17, 2024 15:03
@fenos
Copy link
Collaborator Author

fenos commented Jan 17, 2024

@Murderlon i think it makes a lot of sense to also pass the parsed Metadata in the namingFunction as an optional second param for example:

function namingFunction(req, metadata) {
  if (!metadata) {
     throw new Error('must provide metadata')
  }
  
  // validate metadata
  return metadata.fileName
}

@fenos fenos force-pushed the fix/propagate-error-on-create-hook branch from 3f7fd83 to e73ed0c Compare January 17, 2024 15:14
@Murderlon
Copy link
Member

Sounds good 👍

We can add the metadata argument in this PR as well

@fenos
Copy link
Collaborator Author

fenos commented Jan 17, 2024

Done 🎉

@fenos fenos changed the title @tus/server: propagate error on naming function @tus/server: Metadata on namingFunction + propagate error Jan 17, 2024
@fenos fenos force-pushed the fix/propagate-error-on-create-hook branch from 90ae3c6 to 6b8bc90 Compare January 17, 2024 15:52
@Murderlon Murderlon merged commit a49bc4b into tus:main Jan 17, 2024
@Murderlon
Copy link
Member

I'll do a release tomorrow.

@fenos fenos deleted the fix/propagate-error-on-create-hook branch January 17, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants