-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[LDAP] Add error codes to exceptions #28677
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
Comments
I'd better suggest throw proper exception with given messages |
This PR was merged into the 4.4 branch. Discussion ---------- [Ldap] Add exception for mapping ldap errors | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #28677 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Maybe we could add more exception code since the list has a lot of errors, maybe we could add a class that maps the error to the right exeptions. see https://www.php.net/manual/en/function.ldap-errno.php Commits ------- 1b29cb1 [Ldap] Add exception for mapping ldap errors
I think this is not only relevant for the bind operation, but also for other operations e.g. query. For example I want to catch LDAP_NO_SUCH_OBJECT (error code 32). Currently I'd have to parse the message to do this. So I suggest to reopen this issue. |
@dontub Would you will to submit a pull request for that? |
I just had a deeper look at it. I'm currently thinking about an exception factory like this final class ExceptionFactory
{
public static function createLdapException($messageFormat, $connection)
{
$errorCode = ldap_errno($connection);
$errorMsg = ldap_err2str($errorCode);
$message = strtr($messageFormat, [
'%errorCode%' => $errorCode,
'%errorMsg%' => $errorMsg,
]);
return new LdapException($message, $errorCode);
}
} instead of adding a call to I also found four places where an
Is the last one necessary as the WDYT? In case of the exception factory: Should PHP type hints be used there? |
This PR ensures that an LdapException is only used when an LDAP operations fails. In cases an LdapException was used for non LDAP operations it is replaced by an appropriate exception.
This PR ensures that an LdapException is only used when an LDAP operations fails. In cases an LdapException was used for non LDAP operations it is replaced by an appropriate exception.
Description
Upon LDAP errors, the PHP ldap extension may also return an error code. Using this code may provide a friendlier way to determine the root cause of an issue than to interpret the error message - consider how the following example may be achieved currently, with the LDAP component.
Example
The text was updated successfully, but these errors were encountered: