로그인 실패 exception 처리, saveErrorLogData 오타 수정
This commit is contained in:
@@ -23,6 +23,7 @@ import org.springframework.dao.DuplicateKeyException;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
@@ -48,7 +49,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
|
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
|
||||||
String codeName = "NOT_FOUND_DATA";
|
String codeName = "NOT_FOUND_DATA";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
||||||
@@ -69,7 +70,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[HttpMessageNotReadableException] resource :{} ", e.getMessage());
|
log.warn("[HttpMessageNotReadableException] resource :{} ", e.getMessage());
|
||||||
String codeName = "BAD_REQUEST";
|
String codeName = "BAD_REQUEST";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -90,7 +91,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[NoSuchElementException] resource :{} ", e.getMessage());
|
log.warn("[NoSuchElementException] resource :{} ", e.getMessage());
|
||||||
String codeName = "NOT_FOUND_DATA";
|
String codeName = "NOT_FOUND_DATA";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -111,7 +112,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[handlerIllegalArgumentException] resource :{} ", e.getMessage());
|
log.warn("[handlerIllegalArgumentException] resource :{} ", e.getMessage());
|
||||||
String codeName = "BAD_REQUEST";
|
String codeName = "BAD_REQUEST";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -132,7 +133,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[DataIntegrityViolationException] resource :{} ", e.getMessage());
|
log.warn("[DataIntegrityViolationException] resource :{} ", e.getMessage());
|
||||||
String codeName = "DATA_INTEGRITY_ERROR";
|
String codeName = "DATA_INTEGRITY_ERROR";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
HttpStatus.valueOf("UNPROCESSABLE_ENTITY"),
|
||||||
@@ -153,7 +154,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[MethodArgumentNotValidException] resource :{} ", e.getMessage());
|
log.warn("[MethodArgumentNotValidException] resource :{} ", e.getMessage());
|
||||||
String codeName = "BAD_REQUEST";
|
String codeName = "BAD_REQUEST";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -174,7 +175,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[AccessDeniedException] resource :{} ", e.getMessage());
|
log.warn("[AccessDeniedException] resource :{} ", e.getMessage());
|
||||||
String codeName = "UNAUTHORIZED";
|
String codeName = "UNAUTHORIZED";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -188,6 +189,7 @@ public class GlobalExceptionHandler {
|
|||||||
errorLog.getId());
|
errorLog.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.BAD_GATEWAY)
|
@ResponseStatus(HttpStatus.BAD_GATEWAY)
|
||||||
@ExceptionHandler(HttpServerErrorException.BadGateway.class)
|
@ExceptionHandler(HttpServerErrorException.BadGateway.class)
|
||||||
public ApiResponseDto<String> handlerHttpServerErrorException(
|
public ApiResponseDto<String> handlerHttpServerErrorException(
|
||||||
@@ -195,7 +197,7 @@ public class GlobalExceptionHandler {
|
|||||||
log.warn("[HttpServerErrorException] resource :{} ", e.getMessage());
|
log.warn("[HttpServerErrorException] resource :{} ", e.getMessage());
|
||||||
String codeName = "BAD_GATEWAY";
|
String codeName = "BAD_GATEWAY";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -217,7 +219,7 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
String codeName = "UNPROCESSABLE_ENTITY";
|
String codeName = "UNPROCESSABLE_ENTITY";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -252,7 +254,7 @@ public class GlobalExceptionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf("BAD_REQUEST"),
|
HttpStatus.valueOf("BAD_REQUEST"),
|
||||||
@@ -275,7 +277,7 @@ public class GlobalExceptionHandler {
|
|||||||
String codeName = "NOT_FOUND_USER";
|
String codeName = "NOT_FOUND_USER";
|
||||||
|
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf("BAD_REQUEST"),
|
HttpStatus.valueOf("BAD_REQUEST"),
|
||||||
@@ -298,7 +300,7 @@ public class GlobalExceptionHandler {
|
|||||||
String codeName = "DUPLICATE_DATA";
|
String codeName = "DUPLICATE_DATA";
|
||||||
|
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf("CONFLICT"),
|
HttpStatus.valueOf("CONFLICT"),
|
||||||
@@ -312,6 +314,35 @@ public class GlobalExceptionHandler {
|
|||||||
errorLog.getId());
|
errorLog.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ExceptionHandler(BadCredentialsException.class)
|
||||||
|
public ResponseEntity<ApiResponseDto<String>> handleBadCredentials(
|
||||||
|
BadCredentialsException e, HttpServletRequest request
|
||||||
|
) {
|
||||||
|
log.warn("[BadCredentialsException] resource : {} ", e.getMessage());
|
||||||
|
|
||||||
|
String codeName = "UNAUTHORIZED";
|
||||||
|
|
||||||
|
ErrorLogEntity errorLog =
|
||||||
|
saveErrorLogData(
|
||||||
|
request,
|
||||||
|
ApiResponseCode.getCode(codeName),
|
||||||
|
HttpStatus.valueOf(codeName),
|
||||||
|
ErrorLogDto.LogErrorLevel.WARNING,
|
||||||
|
e.getStackTrace());
|
||||||
|
|
||||||
|
ApiResponseDto<String> body =
|
||||||
|
ApiResponseDto.createException(
|
||||||
|
ApiResponseCode.getCode(codeName),
|
||||||
|
ApiResponseCode.getMessage(codeName),
|
||||||
|
HttpStatus.valueOf(codeName),
|
||||||
|
errorLog.getId());
|
||||||
|
|
||||||
|
return ResponseEntity
|
||||||
|
.status(HttpStatus.UNAUTHORIZED) // 🔥 여기서 401 지정
|
||||||
|
.body(body);
|
||||||
|
}
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
@ExceptionHandler(RuntimeException.class)
|
@ExceptionHandler(RuntimeException.class)
|
||||||
public ApiResponseDto<String> handlerRuntimeException(
|
public ApiResponseDto<String> handlerRuntimeException(
|
||||||
@@ -320,7 +351,7 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
String codeName = "INTERNAL_SERVER_ERROR";
|
String codeName = "INTERNAL_SERVER_ERROR";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -341,7 +372,7 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
String codeName = "INTERNAL_SERVER_ERROR";
|
String codeName = "INTERNAL_SERVER_ERROR";
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request,
|
request,
|
||||||
ApiResponseCode.getCode(codeName),
|
ApiResponseCode.getCode(codeName),
|
||||||
HttpStatus.valueOf(codeName),
|
HttpStatus.valueOf(codeName),
|
||||||
@@ -365,7 +396,7 @@ public class GlobalExceptionHandler {
|
|||||||
* @param stackTrace : 에러 내용
|
* @param stackTrace : 에러 내용
|
||||||
* @return : insert하고 결과로 받은 Entity
|
* @return : insert하고 결과로 받은 Entity
|
||||||
*/
|
*/
|
||||||
private ErrorLogEntity saveErrerLogData(
|
private ErrorLogEntity saveErrorLogData(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
ApiResponseCode errorCode,
|
ApiResponseCode errorCode,
|
||||||
HttpStatus httpStatus,
|
HttpStatus httpStatus,
|
||||||
@@ -422,7 +453,7 @@ public class GlobalExceptionHandler {
|
|||||||
ApiResponseCode apiCode = ApiResponseCode.getCode(codeName);
|
ApiResponseCode apiCode = ApiResponseCode.getCode(codeName);
|
||||||
|
|
||||||
ErrorLogEntity errorLog =
|
ErrorLogEntity errorLog =
|
||||||
saveErrerLogData(
|
saveErrorLogData(
|
||||||
request, apiCode, status, ErrorLogDto.LogErrorLevel.WARNING, e.getStackTrace());
|
request, apiCode, status, ErrorLogDto.LogErrorLevel.WARNING, e.getStackTrace());
|
||||||
|
|
||||||
ApiResponseDto<String> body =
|
ApiResponseDto<String> body =
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class AuthController {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
|
response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
|
||||||
return ApiResponseDto.createOK(new TokenResponse(accessToken));
|
return ApiResponseDto.ok(new TokenResponse(accessToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/refresh")
|
@PostMapping("/refresh")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.kamco.cd.kamcoback.members.dto;
|
package com.kamco.cd.kamcoback.members.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
@@ -10,7 +11,10 @@ import lombok.ToString;
|
|||||||
@ToString(exclude = "password")
|
@ToString(exclude = "password")
|
||||||
public class SignInRequest {
|
public class SignInRequest {
|
||||||
|
|
||||||
|
@Schema(description = "사번", example = "11111")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
@Schema(description = "비밀번호", example = "kamco1234!")
|
||||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
private String password;
|
private String password;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user