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 Error Handling within API #35

Open
Jbond312 opened this issue Apr 16, 2019 · 0 comments
Open

Improve Error Handling within API #35

Jbond312 opened this issue Apr 16, 2019 · 0 comments
Assignees
Labels
MVP Part of the Minimal Viable Product

Comments

@Jbond312
Copy link
Owner

Jbond312 commented Apr 16, 2019

At the moment, the services are throwing exceptions that are being caught in a generic middleware. The services are also able to specify which HTTP status code they want to return to. Whilst this works, I would prefer that the services are agnostic of any HTTP responses and that exceptions are only thrown when something exceptional happens.

Proposed changes:

  • Have each command/query return an object with a base response.
    For example it could look something like:
public class BaseResult
{
	public bool Success {get; set;}
	public string Message {get; set;}
	public string Description {get; set;}
	public ValidationFailures FailureReason {get; set;}
}

public enum ValidationFailures
{
	InvalidRequest,
	Unauthorised
}
  • Controllers are then responsible (as they should be) for returning the correct responses.
  • The exception middleware should only then be used for unhandled exceptions
@Jbond312 Jbond312 added the MVP Part of the Minimal Viable Product label Apr 16, 2019
@Jbond312 Jbond312 self-assigned this Apr 16, 2019
@Jbond312 Jbond312 added in progress Issue is being actively worked on by assignee and removed in progress Issue is being actively worked on by assignee labels Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MVP Part of the Minimal Viable Product
Projects
None yet
Development

No branches or pull requests

1 participant