jumbojett / OpenID-Connect-PHP

Minimalist OpenID Connect client
https://github.com/jumbojett/OpenID-Connect-PHP
Apache License 2.0
615 stars 368 forks source link

Feature Request: Add different Exception Types for different errors #250

Open Sebi2020 opened 3 years ago

Sebi2020 commented 3 years ago

Currently it's really difficult to handle different OpenID errors because the library uses only one exception class. Additionally it does not use exception codes thus requireing the developer to do string matching to actually figure out which error caused the exception.

Please introduce exception codes or different exception classes for different exceptions.

huchim commented 3 years ago

I could suggest to consider "provider exceptions", "validation exceptions", "server exceptions", "network exception" and left "generics exceptions" as OpenIDConnectClientException

Maybe a static method:


private static function throws(Throwable $exception) {
    throw new OpenIDConnectClientException('Errror', 0, $exception);
}

private function foo() {
   self::throw(new OpenIDConnectProviderException('Unable to determine state');
}
Sebi2020 commented 3 years ago

I want to add that meaninigful error codes should be provided as well.

huchim commented 3 years ago

I'm coming from Code Triage and I'm not the repo owner, but I can creates a new PR and ask to owner if he is agree with change.

cc: @jumbojett