Since the very beginning of the project, I thought that the way I was handling errors was tech debt. So, I went ahead and applied a pattern that found interesting while reading through this article. I just adapted it to my needs by changing some details.
Changes introduced in this PR:
Change the HandlerFunc of the handlers to func(w http.ResponseWriter, r *http.Request) error
renderError function now executes a error template located at templates/partials/error.tmpl
Such templates is shown to the user when an error occurs
Add a statusErr struct that represents the errors at the HTTP layer
Type of change
Please delete options that are not relevant.
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
[ ] This change requires a documentation update
How Has This Been Tested?
Tested locally by running into known errors or unintended behaviors.
Checklist:
[x] My code follows the style guidelines of this project
[x] I have performed a self-review of my own code
[x] I have commented my code, particularly in hard-to-understand areas
[x] I have made corresponding changes to the documentation
[x] I have added tests that prove my fix is effective or that my feature works
[x] New and existing unit tests pass locally with my changes
[x] I have checked my code and corrected any misspellings
Add idiomatic error handling
Description
Since the very beginning of the project, I thought that the way I was handling errors was tech debt. So, I went ahead and applied a pattern that found interesting while reading through this article. I just adapted it to my needs by changing some details.
Changes introduced in this PR:
HandlerFunc
of thehandlers
tofunc(w http.ResponseWriter, r *http.Request) error
renderError
function now executes a error template located attemplates/partials/error.tmpl
statusErr
struct that represents the errors at the HTTP layerType of change
Please delete options that are not relevant.
How Has This Been Tested?
Tested locally by running into known errors or unintended behaviors.
Checklist: