Skip to content

Commit f67de3f

Browse files
committed
feat(exception-handling): add ApiException class and global exception handler
1 parent 26e1ea0 commit f67de3f

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

backend/src/main/java/com/park/utmstack/advice/GlobalExceptionHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ public ResponseEntity<?> handleMethodArgumentNotValid(MethodArgumentNotValidExce
6666
return ResponseUtil.buildBadRequestResponse(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
6767
}
6868

69+
@ExceptionHandler(ApiException.class)
70+
public ResponseEntity<?> handleApiException(ApiException ex) {
71+
return ResponseUtil.buildErrorResponse(ex.getStatus(), ex.getMessage());
72+
}
73+
6974
@ExceptionHandler(Exception.class)
7075
public ResponseEntity<?> handleGenericException(Exception e, HttpServletRequest request) {
7176
return ResponseUtil.buildInternalServerErrorResponse(e.getMessage());

backend/src/main/java/com/park/utmstack/aop/logging/NoLogException.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.park.utmstack.aop.logging;
22

3-
import java.lang.annotation.ElementType;
4-
import java.lang.annotation.Retention;
5-
import java.lang.annotation.RetentionPolicy;
6-
import java.lang.annotation.Target;
3+
import java.lang.annotation.*;
74

5+
@Inherited
86
@Target(ElementType.TYPE)
97
@Retention(RetentionPolicy.RUNTIME)
108
public @interface NoLogException {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.park.utmstack.util.exceptions;
2+
3+
import com.park.utmstack.aop.logging.NoLogException;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import org.springframework.http.HttpStatus;
7+
8+
@Getter
9+
@Setter
10+
@NoLogException
11+
public class ApiException extends RuntimeException {
12+
private final String message;
13+
private final HttpStatus status;
14+
15+
public ApiException(String message, HttpStatus status) {
16+
super(message);
17+
this.message = message;
18+
this.status = status;
19+
}
20+
}
21+

0 commit comments

Comments
 (0)