tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
2.92k stars 465 forks source link

Return 4xx errors from Hooks as 4xx errors. #1143

Closed werfmark closed 4 weeks ago

werfmark commented 4 weeks ago

Is your feature request related to a problem? Please describe. In version 1 of the tus server a 4xx error returned from a blocking Hook request would be returned as the same 4xx error by the TUS server. Somehow this functionality was changed to return a 500 error. This makes it difficult to use the Hooks for validation and return nice errors to the client calling the TUS server.

Describe the solution you'd like Return to the functionality there was before where an error on HTTP hook would be propagated by the server instead of turning any error into a 500.

OR

Make a flag in the configuration that you can choose to have 4xx hook errors to be propagated as is or returned as a 500 by the hook server.

Specifically this change altered this (and the documentation was altered at the same time):

https://github.com/tus/tusd/commit/12c10bf62f7b2914da31de768fb2387183ec370d#diff-d5eb1c29219a05ea94e8c599a8f52fa0caf37d4a63b5744e5313037e90e12321L77

Why was this done?

Acconut commented 4 weeks ago

This change was made for various reasons when the entire hook system was overhauled for tusd v2. The new approach allows us to properly intingush between error responses that should be forwarded to the client and internal errors that indicate a failure while executing the hook. Furthermore, the new system provides a unified way of exchanging information between tusd and the hook implementation across the different hook systems (HTTP, file, gRPC etc).

In fact, the new hook system is much more powerful and allows you to completely control the response status, headers, and body by returning a corresponding hook response. Please consult https://tus.github.io/tusd/advanced-topics/hooks/#hook-requests-and-responses for more details. Does that not work for you?

werfmark commented 4 weeks ago

Thanks for the quick answer.

That makes sense, we were already expecting some sort of feature like this but glossed over this in the changes from version 1 to version 2 of the tusd server. We will take a look at this but at first glance seems to be much more powerful and versatile so should fit our purposes just fine.

Acconut commented 4 weeks ago

but glossed over this in the changes from version 1 to version 2 of the tusd server

We've all been there :) Glad it helped!