I have some code that proxies LDAP messages. The code implements handlers of ApacheDS by calling LDAP servers using JNDI. When an error is returned from the LDAP server, JNDI reports it as an javax.naming.NamingException (or subclass) like:
AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
On the other hand we need to return an answer to the client through the ApacheDS sink using an error code enum:
ResultCodeEnum resultCodeEnum = ResultCodeEnum.getResultCode(errorCode);
ldapResult.setResultCode(resultCodeEnum);
How can I extract the "error code" number from the JNDI javax.naming.NamingException? (of course I can always parse the 'error code' from NamingException.explanation, if a number is found in explanation, but I'm looking for a library solution)