Begin error handling rework #58
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I'm changing
This PR attempts to wrangle the errors within the handlers to support better logging.
Currently, we are exploring mysterious
404responses when theget_objectendpoint is being overwhelmed. While handling this endpoint, errors such asErr(())are thrown, smothering any information about the underlying cause of failure.How I did it
Utilize the
thiserrorcrate to create an enum of possible failures.Tip
This is the PR is the beginning of transitioning the entirety of the codebase to make use of our
thiserrorenum. Eventually, this enum will replace theApiErrortrait that we are currently using:data.source.coop/src/utils/errors.rs
Lines 66 to 68 in 802ab2a
In an attempt to reduce boilerplate code, I created a helper
process_json_responsefunction to handle routine errors from the Source API (not the proxy, but the API managed in https://github.com/source-cooperative/source.coop/). I feel like there may be a better way to do this.data.source.coop/src/utils/api.rs
Lines 6 to 43 in 802ab2a
Errors are raised and handled within the API controller, where they are logged. Being that
thiserrorimplements theDisplaytrait, I believe that the logs should render the error messages as described in the enum:data.source.coop/src/main.rs
Lines 84 to 93 in 802ab2a
data.source.coop/src/utils/errors.rs
Lines 9 to 17 in 802ab2a
The
Fromtrait allows these errors to be translated into appropriate HTTP Responses:data.source.coop/src/utils/errors.rs
Lines 38 to 64 in 802ab2a
Along the way, I attempted to flatten the deeply nested
matchstatements found within the code.PR Checklist:
and I have opened issue/PR #XXX to track the change.