1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.data.ldaptive;
18
19 import lombok.EqualsAndHashCode;
20 import org.bremersee.exception.AbstractServiceExceptionBuilder;
21 import org.bremersee.exception.ErrorCodeAware;
22 import org.bremersee.exception.HttpStatusAware;
23 import org.bremersee.exception.ServiceException;
24 import org.bremersee.exception.ServiceExceptionBuilder;
25 import org.ldaptive.LdapException;
26 import org.ldaptive.ResultCode;
27
28
29
30
31
32
33 @EqualsAndHashCode(callSuper = true)
34 public class LdaptiveException extends ServiceException implements HttpStatusAware, ErrorCodeAware {
35
36 private static final long serialVersionUID = 1L;
37
38
39
40
41
42
43
44 protected LdaptiveException(final int httpStatus, final String errorCode) {
45 super(httpStatus, errorCode);
46 }
47
48
49
50
51
52
53
54
55 protected LdaptiveException(final int httpStatus, final String errorCode, final String reason) {
56 super(httpStatus, errorCode, reason);
57 }
58
59
60
61
62
63
64
65
66 protected LdaptiveException(final int httpStatus, final String errorCode, final Throwable cause) {
67 super(httpStatus, errorCode, cause);
68 }
69
70
71
72
73
74
75
76
77
78 protected LdaptiveException(
79 final int httpStatus,
80 final String errorCode,
81 final String reason,
82 final Throwable cause) {
83 super(httpStatus, errorCode, reason, cause);
84 }
85
86
87
88
89
90
91
92 public LdapException getLdapException() {
93 return getCause() instanceof LdapException ? (LdapException) getCause() : null;
94 }
95
96
97
98
99
100
101 @SuppressWarnings("unused")
102 public ResultCode getResultCode() {
103 final LdapException ldapException = getLdapException();
104 return ldapException != null ? ldapException.getResultCode() : null;
105 }
106
107
108
109
110
111
112 public static ServiceExceptionBuilder<LdaptiveException> builder() {
113 return new AbstractServiceExceptionBuilder<>() {
114
115 private static final long serialVersionUID = 2L;
116
117 @Override
118 protected LdaptiveException buildWith(int httpStatus, String errorCode) {
119 return new LdaptiveException(httpStatus, errorCode);
120 }
121
122 @Override
123 protected LdaptiveException buildWith(int httpStatus, String errorCode, String reason) {
124 return new LdaptiveException(httpStatus, errorCode, reason);
125 }
126
127 @Override
128 protected LdaptiveException buildWith(int httpStatus, String errorCode, Throwable cause) {
129 return new LdaptiveException(httpStatus, errorCode, cause);
130 }
131
132 @Override
133 protected LdaptiveException buildWith(int httpStatus, String errorCode, String reason,
134 Throwable cause) {
135 return new LdaptiveException(httpStatus, errorCode, reason, cause);
136 }
137 };
138 }
139
140 }