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

wrap errors for easier handling in external services #221

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

mikemrm
Copy link
Contributor

@mikemrm mikemrm commented Mar 7, 2024

Services wanting to check if the error returned was an auth error or some other error could get a number of auth related errors.

This wraps the permissions and auth errors into easily comparable root errors for easier checks.

Additionally this corrects the incorrectly returned echo errors which were missing for PermissionDenied errors which resulted in 500 errors.

Services wanting to check if the error returned was an auth error or
some other error could get a number of auth related errors.

This wraps the permissions and auth errors into easily comparable root
errors for easier checks.

Additionally this corrects the incorrectly returned echo errors which
were missing for PermissionDenied errors which resulted in 500 errors.

Signed-off-by: Mike Mason <[email protected]>
@mikemrm mikemrm requested review from a team as code owners March 7, 2024 16:53
// ErrNoAuthToken is the error returned when there is no auth token provided for the API request
ErrNoAuthToken = errors.New("no auth token provided for client")
ErrNoAuthToken = echo.ErrBadRequest.WithInternal(fmt.Errorf("%w: no auth token provided for client", AuthError))
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrapping these makes sense, but is this the right place for it? The permissions client and Echo middleware aren't really the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ErrNoAuthToken is only used by the echo middleware portion of this package.

Not all errors are wrapped in echo errors, such as ErrPermissionsMiddlewareMissing is used with events.

Echo already handles errors which are not echo http errors as 500 by default, so I only wrapped errors which we return in the echo middleware which we want something other than a 500 for.

@mikemrm mikemrm requested a review from jnschaeffer March 7, 2024 18:22
@mikemrm mikemrm merged commit 97f201e into infratographer:main Mar 15, 2024
4 checks passed
@mikemrm mikemrm deleted the wrap-errors branch March 15, 2024 15:09
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