@tus/server: introduce onErrorResponse hook #522
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR replaces #518 in favour of a new approach.
A legitimate use case for this hook which I think is worth considering is:
Custom logging. In the PR you mentioned above doesn't really solve the issue because we might want to send the error somewhere in Sentry or in any error reporter of choice in a specific format. Having this hook would make it possible to do just that.
Centralizing the mapping of application-specific errors to Tus HTTP errors.
This use case I think is quite important since application-specific errors can be thrown in many different places not only on onUploadCreate , onUploadFinish but potentially in all the events hooks emitted as well in custom Locks implementations.
By centralising the mapping of error handling we don't need to try/catch everywhere and do the mapping in place, this allows for better maintainability in the long run.
I have changed the implementation slightly from the original PR and now the onErrorResponse doesn't actually allow to write the response but can be used as follows:
overall is a neat way to keep things tidy and centralised