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

fix(api-server): improve HandleError to handle rest_errors.Error and fix Unauthenticated error handling #7818

Conversation

bartsmykla
Copy link
Contributor

  • Update HandleError to process pointer to rest_errors.Error as an argument. This allows us to use errors.As directly, which simplifies the code and allows project depending on Kuma to handle not hardcoded errors.

  • Fix a bug in HandleError where it was incorrectly assigning err to itself in the case of an Unauthenticated error.

Checklist prior to review

  • Link to relevant issue as well as docs and UI issues
  • This will not break child repos: it doesn't hardcode values (.e.g "kumahq" as a image registry) and it will work on Windows, system specific functions like syscall.Mkfifo have equivalent implementation on the other OS
    • It won't
  • Tests (Unit test, E2E tests, manual test on universal and k8s)
    • Manually tested
  • Do you need to update UPGRADE.md?
    • There is no need
  • Does it need to be backported according to the backporting policy? (this GH action will add "backport" label based on these file globs, if you want to prevent it from adding the "backport" label use no-backport-autolabel label)
    • There is no need
  • Do you need to explicitly set a > Changelog: entry here or add a ci/ label to run fewer/more tests?

…Unauthenticated error handling

* Update HandleError to process pointer to rest_errors.Error
  as an argument. This allows us to use errors.As directly,
  which simplifies the code and slightly improves performance.

* Fix a bug in HandleError where it was incorrectly assigning
  err to itself in the case of an Unauthenticated error.

Signed-off-by: Bart Smykla <[email protected]>
@bartsmykla bartsmykla requested a review from a team as a code owner September 22, 2023 11:53
@bartsmykla bartsmykla enabled auto-merge (squash) September 22, 2023 12:24
@bartsmykla bartsmykla merged commit a4e04d2 into kumahq:master Sep 22, 2023
Status: 403,
Title: "Access Denied",
Detail: accessErr.Reason,
}
case errors.Is(err, &Unauthenticated{}):
var unauthenticated *Unauthenticated
errors.As(err, &err)
kumaErr = types.Error{
errors.As(err, &unauthenticated)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just use _ if we know this will return true instead of ignoring

@lahabana lahabana changed the title fix(errors): improve HandleError to handle rest_errors.Error and fix Unauthenticated error handling fix(api-server): improve HandleError to handle rest_errors.Error and fix Unauthenticated error handling Nov 3, 2023
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.

Bug in rest error handling for Unauthenticated
3 participants