-
Notifications
You must be signed in to change notification settings - Fork 27
Improve error messages for "Bad Request" responses #257
Description
Relates to: #255
While I was debugging the issue #255 I had to add a lot of "print" statements to find out what was to error. In the torrent API context we are returning a lot of ServiceError::BadRequest. See the handler mod.
We should replace all of them with a custom service error or at least with a service error which contains the reason why it failed. As all service errors have only one error message, now I would follow the convention and create a single error for each case. In the future, we could join some of them, for example, ServiceError::InvalidMultipartForm.
On the other hand, maybe errors in the handlers mod should not be a new Service error case. These errors belong to the web server framework. SeriveError should be used only in the domain service layer. It seems the torrent context handlers are the only ones using the ServiceError directly (not a domain service response), especially the function get_torrent_request_from_payload. I would add a new type of error for the handlers layer. It could be one type for all API contexts or we could add an error mod inside all API contexts. I prefer the second option.
Conclusion
- Add a new
error.rsmod inside the API torrent context. - Add a new struct
HandlerError. - Replace all SeriviceError with the new type. Do not use a generic BadRequest error. Define a specific enum case for each case.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status