Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b26b0b

Browse files
feat(spring dependent): make CustomException extend BaseCustomException
1 parent bd5d065 commit 2b26b0b

File tree

1 file changed

+8
-99
lines changed

1 file changed

+8
-99
lines changed
Lines changed: 8 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,45 @@
11
package letsdev.common.exception.support;
22

3-
import org.springframework.http.HttpStatus;
4-
5-
import java.util.Collections;
63
import java.util.Map;
74
import java.util.function.Supplier;
85

9-
public class CustomException extends RuntimeException {
10-
11-
protected final ErrorCode errorCode;
12-
protected final Runnable action;
13-
protected final Supplier<Map<String, Object>> payloadSupplier;
6+
public class CustomException extends BaseCustomException {
147

158
public CustomException() {
16-
super(getDefaultErrorCode().message());
17-
this.errorCode = getDefaultErrorCode();
18-
this.action = () -> {};
19-
this.payloadSupplier = Collections::emptyMap;
9+
super();
2010
}
2111

2212
public CustomException(String message) {
2313
super(message);
24-
this.errorCode = getDefaultErrorCode();
25-
this.action = () -> {};
26-
this.payloadSupplier = Collections::emptyMap;
2714
}
2815

2916
public CustomException(String message, Throwable cause) {
3017
super(message, cause);
31-
this.errorCode = getDefaultErrorCode();
32-
this.action = () -> {};
33-
this.payloadSupplier = Collections::emptyMap;
3418
}
3519

3620
public CustomException(ErrorCode errorCode) {
37-
super(errorCode.message());
38-
this.errorCode = errorCode;
39-
this.action = () -> {};
40-
this.payloadSupplier = Collections::emptyMap;
21+
super(errorCode);
4122
}
4223

4324
public CustomException(ErrorCode errorCode, Throwable cause) {
44-
super(errorCode.message(), cause);
45-
this.errorCode = errorCode;
46-
this.action = () -> {};
47-
this.payloadSupplier = Collections::emptyMap;
25+
super(errorCode, cause);
4826
}
4927

5028
public CustomException(ErrorCode errorCode, Runnable action) {
51-
super(errorCode.message());
52-
this.errorCode = errorCode;
53-
this.action = action;
54-
this.payloadSupplier = Collections::emptyMap;
29+
super(errorCode, action);
5530
}
5631

5732
public CustomException(ErrorCode errorCode, Runnable action, Throwable cause) {
58-
super(errorCode.message(), cause);
59-
this.errorCode = errorCode;
60-
this.action = action;
61-
this.payloadSupplier = Collections::emptyMap;
33+
super(errorCode, action, cause);
6234

6335
}
6436

6537
public CustomException(ErrorCode errorCode, Supplier<Map<String, Object>> payloadSupplier) {
66-
super(errorCode.message());
67-
this.errorCode = errorCode;
68-
this.action = () -> {};
69-
this.payloadSupplier = payloadSupplier;
38+
super(errorCode, payloadSupplier);
7039

7140
}
7241

7342
public CustomException(ErrorCode errorCode, Supplier<Map<String, Object>> payloadSupplier, Throwable cause) {
74-
super(errorCode.message(), cause);
75-
this.errorCode = errorCode;
76-
this.action = () -> {};
77-
this.payloadSupplier = payloadSupplier;
78-
}
79-
80-
private static ErrorCode getDefaultErrorCode() {
81-
return DefaultErrorCodeHolder.DEFAULT_ERROR_CODE;
82-
}
83-
84-
public ErrorCode getErrorCode() {
85-
return errorCode;
86-
}
87-
88-
private static class DefaultErrorCodeHolder { // 사용할 때 로드 + 스레드 세이프(클래스 로드 타임은 동시성 보장됨.)
89-
private static final ErrorCode DEFAULT_ERROR_CODE = new ErrorCode() {
90-
@Override
91-
public String name() {
92-
return "SERVER_ERROR";
93-
}
94-
95-
@Override
96-
public HttpStatus httpStatus() {
97-
return HttpStatus.INTERNAL_SERVER_ERROR;
98-
}
99-
100-
@Override
101-
public String message() {
102-
return "서버 오류";
103-
}
104-
105-
@Override
106-
public CustomException exception() {
107-
return new CustomException(this);
108-
}
109-
110-
@Override
111-
public CustomException exception(Throwable cause) {
112-
return new CustomException(this, cause);
113-
}
114-
115-
@Override
116-
public CustomException exception(Runnable action) {
117-
return new CustomException(this, action);
118-
}
119-
120-
@Override
121-
public CustomException exception(Runnable action, Throwable cause) {
122-
return new CustomException(this, action, cause);
123-
}
124-
125-
@Override
126-
public CustomException exception(Supplier<Map<String, Object>> payloadSupplier) {
127-
return new CustomException(this, payloadSupplier);
128-
}
129-
130-
@Override
131-
public CustomException exception(Supplier<Map<String, Object>> payloadSupplier, Throwable cause) {
132-
return new CustomException(this, payloadSupplier, cause);
133-
}
134-
};
43+
super(errorCode, payloadSupplier, cause);
13544
}
13645
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /