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.io.Serial;
20 import lombok.EqualsAndHashCode;
21 import org.bremersee.exception.AbstractServiceExceptionBuilder;
22 import org.bremersee.exception.ErrorCodeAware;
23 import org.bremersee.exception.HttpStatusAware;
24 import org.bremersee.exception.ServiceException;
25 import org.bremersee.exception.ServiceExceptionBuilder;
26 import org.ldaptive.LdapException;
27 import org.ldaptive.ResultCode;
28
29
30
31
32
33
34 @EqualsAndHashCode(callSuper = true)
35 public class LdaptiveException extends ServiceException implements HttpStatusAware, ErrorCodeAware {
36
37 @Serial
38 private static final long serialVersionUID = 1L;
39
40
41
42
43
44
45
46
47
48 protected LdaptiveException(
49 int httpStatus,
50 String errorCode,
51 String reason,
52 Throwable cause) {
53 super(httpStatus, errorCode, reason, cause);
54 }
55
56
57
58
59
60
61 public LdapException getLdapException() {
62 if (getCause() instanceof LdapException le) {
63 return le;
64 }
65 return null;
66 }
67
68
69
70
71
72
73 public ResultCode getResultCode() {
74 LdapException ldapException = getLdapException();
75 return ldapException != null ? ldapException.getResultCode() : null;
76 }
77
78
79
80
81
82
83 public static ServiceExceptionBuilder<LdaptiveException> builder() {
84
85 return new AbstractServiceExceptionBuilder<>() {
86
87 @Serial
88 private static final long serialVersionUID = 2L;
89
90 @Override
91 protected LdaptiveException buildWith(int httpStatus, String errorCode, String reason,
92 Throwable cause) {
93 return new LdaptiveException(httpStatus, errorCode, reason, cause);
94 }
95 };
96 }
97
98 }