-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from kusitms-28th-Meetup-E/feat/global
Feat/global
- Loading branch information
Showing
14 changed files
with
190 additions
and
98 deletions.
There are no files selected for viewing
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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/gwangjang/server/exception/ApplicationException.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,23 @@ | ||
package gwangjang.server.exception; | ||
|
||
import gwangjang.server.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public abstract class ApplicationException extends RuntimeException { | ||
|
||
private final ErrorCode errorCode; | ||
private final HttpStatus httpStatus; | ||
|
||
protected ApplicationException(ErrorCode errorCode, HttpStatus httpStatus) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
this.httpStatus = httpStatus; | ||
} | ||
|
||
public ErrorCode getErrorCode() { return errorCode;} | ||
|
||
public HttpStatus getHttpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/gwangjang/server/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,64 @@ | ||
//package gwangjang.server.exception; | ||
// | ||
//import gwangjang.server.response.ErrorCode; | ||
//import gwangjang.server.response.ErrorResponse; | ||
//import lombok.extern.slf4j.Slf4j; | ||
//import org.springframework.context.support.DefaultMessageSourceResolvable; | ||
//import org.springframework.http.HttpStatus; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.http.converter.HttpMessageNotReadableException; | ||
//import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
//import org.springframework.web.bind.MethodArgumentNotValidException; | ||
//import org.springframework.web.bind.annotation.ExceptionHandler; | ||
//import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
// | ||
//import java.util.function.Consumer; | ||
//import java.util.regex.PatternSyntaxException; | ||
//import java.util.stream.Collectors; | ||
// | ||
//@RestControllerAdvice | ||
//@Slf4j | ||
//public class GlobalExceptionHandler { | ||
// | ||
// private static final String LOG_FORMAT = "Class : {}, Code : {}, Message : {}"; | ||
// | ||
// @ExceptionHandler(ApplicationException.class) | ||
// public ResponseEntity<ErrorResponse> handleApplicationException(ApplicationException ex) { | ||
// return handleException(ex, ex.getErrorCode(), ex.getMessage(), ex.getHttpStatus(), log::warn); | ||
// } | ||
// | ||
// @ExceptionHandler(MethodArgumentNotValidException.class) | ||
// public ResponseEntity<ErrorResponse> inputMethodArgumentInvalidExceptionHandler (MethodArgumentNotValidException ex) { | ||
// String message = ex.getBindingResult().getFieldErrors().stream() | ||
// .map(DefaultMessageSourceResolvable::getDefaultMessage) | ||
// .collect(Collectors.joining(", ")); | ||
// return handleException(ex, ErrorCode.BAD_REQUEST, message, HttpStatus.BAD_REQUEST, log::warn); | ||
// } | ||
// | ||
// @ExceptionHandler(PatternSyntaxException.class) | ||
// public ResponseEntity<ErrorResponse> inputPatternSyntaxExceptionHandler(PatternSyntaxException ex) { | ||
// return handleException(ex, ErrorCode.BAD_REQUEST, ErrorCode.BAD_REQUEST.getMessage(), HttpStatus.BAD_REQUEST, log::warn); | ||
// } | ||
// | ||
// @ExceptionHandler(HttpMessageNotReadableException.class) | ||
// public ResponseEntity<ErrorResponse> jsonParseExceptionHandler(HttpMessageNotReadableException ex) { | ||
// return handleException(ex, ErrorCode.BAD_REQUEST, ErrorCode.BAD_REQUEST.getMessage(), HttpStatus.BAD_REQUEST, log::warn); | ||
// } | ||
// | ||
// @ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
// public ResponseEntity<ErrorResponse> httpRequestNotSupportedExceptionHandler(HttpRequestMethodNotSupportedException ex) { | ||
// return handleException(ex, ErrorCode.METHOD_NOT_ALLOWED, ErrorCode.METHOD_NOT_ALLOWED.getMessage(), HttpStatus.METHOD_NOT_ALLOWED, log::warn); | ||
// } | ||
// | ||
// @ExceptionHandler(Exception.class) | ||
// public ResponseEntity<ErrorResponse> internalServerErrorHandler(Exception ex) { | ||
// return handleException(ex, ErrorCode.INTERNAL_SERVER_ERROR, ErrorCode.INTERNAL_SERVER_ERROR.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, log::error); | ||
// } | ||
// | ||
// private ResponseEntity<ErrorResponse> handleException(Exception ex, ErrorCode errorCode, String message, HttpStatus httpStatus, Consumer<String> logger) { | ||
// log.error(LOG_FORMAT, ex.getClass().getSimpleName(), errorCode.getErrorCode(), ex.getMessage()); | ||
// ErrorResponse errorResponse = new ErrorResponse(errorCode, message); | ||
// return ResponseEntity.status(httpStatus.value()).body(errorResponse); | ||
// } | ||
// | ||
//} |
6 changes: 6 additions & 0 deletions
6
src/main/java/gwangjang/server/exception/InternalServerErrorException.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,6 @@ | ||
package gwangjang.server.exception; | ||
|
||
public class InternalServerErrorException extends RuntimeException{ | ||
|
||
public InternalServerErrorException(String message){ super(message); } | ||
} |
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
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
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
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
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,26 @@ | ||
package gwangjang.server.handler; | ||
|
||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
|
||
@Configuration | ||
public class SwaggerConfig { | ||
// @Bean | ||
// public OpenAPI openAPI() { | ||
// return new OpenAPI() | ||
// .components(new Components()) | ||
// .info(apiInfo()); | ||
// } | ||
// | ||
// private Info apiInfo() { | ||
// return new Info() | ||
// .title("Springdoc 테스트") | ||
// .description("Springdoc을 사용한 Swagger UI 테스트") | ||
// .version("1.0.0"); | ||
// } | ||
} |
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
Oops, something went wrong.