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

feature: Add helper functions for working with errors #461

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

nesv
Copy link
Contributor

@nesv nesv commented Mar 1, 2024

📝 Description

This pull request adds two functions to the public API for this package:

  • ErrHasStatus(error, ...int) attempts to unwrap the provided error to an *Error and see if its status code matches any of the status codes provided.
  • IsNotFound is a thin wrapper over ErrHasStatus(err, http.StatusNotFound) for a subjectively-common use case.

Implements #460

✔️ How to Test

make testunit

@nesv nesv requested a review from a team as a code owner March 1, 2024 21:38
@nesv nesv requested review from jriddle-linode and zliang-akamai and removed request for a team March 1, 2024 21:38
This pull request adds two functions to the public API for this package:

* `ErrHasStatus(error, ...int)` attempts to unwrap the provided
  error to an `*Error` and see if its status code matches any of the
  status codes provided.
* `IsNotFound` is a thin wrapper over ErrHasStatus(err, http.StatusNotFound).
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for your contribution!

@nesv
Copy link
Contributor Author

nesv commented Mar 7, 2024

LGTM. Thanks for your contribution!

You're most welcome, @zliang-akamai!

I had a thought earlier: should these "helper" functions exist in the base package for the module, or do you think they could/should be moved into a errutil package (i.e. github.com/linode/linodego/errutil)?

@zliang-akamai zliang-akamai requested review from a team, ykim-1 and yec-akamai and removed request for a team March 7, 2024 18:49
Copy link
Contributor

@ykim-1 ykim-1 left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@zliang-akamai
Copy link
Member

Hi @nesv, I think it will be fine to remain in the base package for now. We can discuss moving it to an error related sub-package in the future when the base package becomes larger.

@zliang-akamai zliang-akamai merged commit 74a7135 into linode:main Mar 18, 2024
4 checks passed
@zliang-akamai zliang-akamai linked an issue Mar 18, 2024 that may be closed by this pull request
@zliang-akamai zliang-akamai added the new-feature for new features in the changelog. label Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature for new features in the changelog.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Helper functions for working with errors
3 participants