1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.ldaptive;
18
19 import java.util.Optional;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.ldaptive.LdapException;
23
24
25
26
27
28
29 public abstract class AbstractLdaptiveErrorHandler implements LdaptiveErrorHandler {
30
31 private static final Log log = LogFactory.getLog(AbstractLdaptiveErrorHandler.class);
32
33
34
35
36 protected AbstractLdaptiveErrorHandler() {
37 super();
38 }
39
40 @Override
41 public void handleError(Throwable t) {
42 final LdaptiveException ldaptiveException;
43 if (t instanceof LdaptiveException le) {
44 ldaptiveException = le;
45 } else if (t instanceof LdapException le) {
46 ldaptiveException = map(le);
47 } else {
48 ldaptiveException = LdaptiveException.builder()
49 .reason(Optional.ofNullable(t)
50 .filter(Exception.class::isInstance)
51 .map(Throwable::getMessage)
52 .orElse("Unknown"))
53 .cause(t)
54 .build();
55 }
56 log.error("LDAP operation failed.", ldaptiveException);
57 throw ldaptiveException;
58 }
59
60 }