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

Add basic error handling framework and 404 handling #50

Merged
merged 14 commits into from
Jul 18, 2023

Conversation

RichDom2185
Copy link
Member

  • Added basic error handling framework
  • Do not crash server (panic) on errors

Part of #49.

Only updated one controller as a minimal example. Remaining controllers will be updated in a future PR


Overview

There are 2 kinds of errors:

  • Client errors: Not Found, Bad Request, etc..
  • Everything else: Internal Server Error

We use a custom error interface ClientError for our errors that have a custom status code. This allows us to create custom error messages, such as those in HandleDBError.


Screenshots

Previously, reading an invalid user gives the wrong status code and output:

image

Now, reading an invalid user will give the correct result:

image

Prevents conflicts with Golang's default errors package.
Done in order to satisfy the error interface.
* Modify model function signature to also return error
* Handle error in controller
* Update users' read handler signature to return errors
* Do not panic on controller error
* Wrap controller with API error handler to show correct status code
@github-actions
Copy link

github-actions bot commented Jul 18, 2023

Coverage Status

coverage: 60.976% (-3.5%) from 64.516% when pulling 1291080 on add-basic-404-handling into 5bd4e88 on main.

@RichDom2185 RichDom2185 self-assigned this Jul 18, 2023
@RichDom2185 RichDom2185 enabled auto-merge (squash) July 18, 2023 04:40
@RichDom2185 RichDom2185 merged commit c9439a9 into main Jul 18, 2023
@RichDom2185 RichDom2185 deleted the add-basic-404-handling branch July 18, 2023 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants