-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add code for each Exception #456
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this! It's an interesting addition. I've made one suggestion - which is that if we are going to use error codes, they should be unique across the library.
It would be even better if the exception codes are 'unique' within the php ecosystem: When translating exceptions, consumers probably use a global exception handler to catch things and global exception code uniqueness could help here - when multiple different libs don't throw "1" as exception code. One approach is to use timestamp of "now" (timestamp when the exception is added, easy to generate with eg. The int itself isn't important as such since you have the class constants in ExceptionCodes already, there is no good reason to enumerate them? What do you think? |
Use case of unique exception codes: |
I don't see this as a good approach. In my opinion, this package should not care about how other apps will use the codes. This package should only make sure that it will always return a unique code ID for each error. So, for example, I'm planning to use these error codes, and create a wrapper, that will translate the exceptions in case I know the error code.
And, I would implement handleException like this:
So, if at some point, the exception codes of the library will be changed, I will not need to do anything on my code. Also, with this example, you can convert these error codes to be unique in your app. For example, for JWT, I want to have error codes from 2000.
|
I get why you want codes in a reasonable range when using them with your approach. |
|
||
namespace Firebase\JWT; | ||
|
||
class ExceptionCodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making this an interface (such as JwtException
) and then having the Exceptions here all implement that interface.
Adding a code for each exception will allow us to translate the exception messages and also offer a simple way to find what exception is thrown.
Issue-455