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

Improve Bad Request error message for uploading #259

Merged
merged 1 commit into from
Aug 23, 2023
Merged

Improve Bad Request error message for uploading #259

merged 1 commit into from
Aug 23, 2023

Conversation

josecelano
Copy link
Member

Add a custom error for each case so that the Bad Request response constains a descriptive error message.

@josecelano josecelano linked an issue Aug 21, 2023 that may be closed by this pull request
3 tasks
@josecelano josecelano changed the title Improve bad request error message for uploading Improve Bad Request error message for uploading Aug 21, 2023
@josecelano josecelano marked this pull request as ready for review August 21, 2023 16:45
@josecelano josecelano requested a review from da2ce7 August 21, 2023 16:45
Copy link
Contributor

@da2ce7 da2ce7 left a comment

Choose a reason for hiding this comment

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

Looks good, however why not just call the enum: Error, instead of HandlerError ?

@josecelano
Copy link
Member Author

josecelano commented Aug 21, 2023

Looks good, however why not just call the enum: ´Error, instead of HandlerError` ?

I was looking for a name to differentiate this error (HandlerError) type from the ServiceError. Each error is thrown at a different app layer (presentation/delivery/UI and domain services). For me, the handler is what other web frameworks call "controller"·

If we remove the prefix, we should also remove the prefix from the ServiceError, should not we?

Other alternatives:

  • WebError
  • RequestError
  • WebRequestError
  • DeliveryError

In fact, maybe we should not use the suffix Error because the struct is inside the errors mod.

I think WebError is the best option I have now. If we have console commands, we could call them ConsoleError. I would like to use a name that quickly identifies the way the user is interacting with the application (delivery layer): console, WEB.

Usually, this type of error is thrown from handlers, that's why I call it HandlerError.

@da2ce7
Copy link
Contributor

da2ce7 commented Aug 21, 2023

I like the name RequestError as it is the most explicit about what the error is about, (not the detail of the handler).

edit: Or even use errors::Request.

Add a custom error for each case so that the Bad Request response
constains a descriptive error message.
@josecelano
Copy link
Member Author

I like the name RequestError as it is the most explicit about what the error is about, (not the detail of the handler).

edit: Or even use errors::Request.

I've updated it. Now you can read:

  • errors::Request::DescriptionIsNotValidUtf8
  • errors::Request::TagsArrayIsNotValidJson
  • ...

I came up with another alternative:

errors::BadRequest::DescriptionIsNotValidUtf8 (this implies two types of errors, not all of them are bad requests, the other type would be errors::RequestProcessing or errors::RequestHandling)

@josecelano josecelano merged commit 2cf80bc into torrust:develop Aug 23, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Improve error messages for "Bad Request" responses
2 participants