-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
be/src/main/java/com/issuetrackermax/common/exception/ApiException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.issuetrackermax.common.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ApiException extends RuntimeException { | ||
private final HttpStatus httpStatus; | ||
private final String message; | ||
|
||
@Builder | ||
private ApiException(HttpStatus httpStatus, String message) { | ||
this.httpStatus = httpStatus; | ||
this.message = message; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
be/src/main/java/com/issuetrackermax/common/exception/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.issuetrackermax.common.exception; | ||
|
||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import com.issuetrackermax.controller.ApiResponse; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
@ExceptionHandler(ApiException.class) | ||
public ApiResponse<ErrorResponse> apiExceptionHandler(ApiException e) { | ||
ErrorCode errorCode = new ErrorCode(e.getHttpStatus().value(), e.getMessage()); | ||
return ApiResponse.exception(ErrorResponse.exception(errorCode)); | ||
} | ||
} |