Skip to content

Commit

Permalink
Merge pull request #42 from Nook-Book/develop
Browse files Browse the repository at this point in the history
[FIX] ErrorResponse ๊ด€๋ จ ์—๋Ÿฌ ์ˆ˜์ • ๋ฐ oauth2 ์„ค์ • ํŒŒ์ผ ๊ตฌ์กฐ ๋ณ€๊ฒฝ์— ๋”ฐ๋ฅธ ์ˆ˜์ •
  • Loading branch information
EunbeenDev authored Dec 3, 2024
2 parents 73c997d + 17a4188 commit a3059c0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
@RequiredArgsConstructor
public class IdTokenVerifier {

@Value("${app.auth.kakao.userInfoUri}")
@Value("${spring.security.oauth2.client.provider.kakao.user-info-uri}")
private String kakaoUserInfoUri;
@Value("${app.auth.tokenSecret}")
@Value("${app.auth.token-secret}")
private String jwtSecret;

private static final Logger logger = LoggerFactory.getLogger(IdTokenVerifier.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
@Component
public class JwtTokenUtil {

@Value("${app.auth.tokenSecret}")
@Value("${app.auth.token-secret}")
private String jwtSecret; // Base64๋กœ ์ธ์ฝ”๋”ฉ๋œ Secret Key

@Value("${app.auth.tokenExpirationMsec}")
@Value("${app.auth.access-token-expiration-msec}")
private long jwtExpirationInMs;

@Value("${app.auth.refreshTokenExpirationMsec}")
@Value("${app.auth.refresh-token-expiration-msec}")
private long jwtRefreshExpirationInMs;

private SecretKey getSigningKey() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,21 @@ public class GlobalExceptionHandler {
public ResponseEntity<ErrorResponse> handleDefaultException(DefaultException ex) {
ErrorCode errorCode = ex.getErrorCode();
ErrorResponse errorResponse = ErrorResponse.builder()
.code(errorCode.getCode())
.status(errorCode.getStatus())
.message(errorCode.getMessage())
.build();
.code(errorCode).build();
return new ResponseEntity<>(errorResponse, HttpStatus.valueOf(errorCode.getStatus()));
}

@ExceptionHandler(NotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFoundException(NotFoundException ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.code("NOT_FOUND")
.status(404)
.message(ex.getMessage())
.build();
.code(ErrorCode.NOT_FOUND).build();
return new ResponseEntity<>(errorResponse, HttpStatus.NOT_FOUND);
}

@ExceptionHandler(DuplicateException.class)
public ResponseEntity<ErrorResponse> handleDuplicateException(DuplicateException ex) {
ErrorResponse errorResponse = ErrorResponse.builder()
.code("DUPLICATE_ERROR")
.status(409)
.message(ex.getMessage())
.build();
.code(ErrorCode.DUPLICATE_ERROR).build();
return new ResponseEntity<>(errorResponse, HttpStatus.CONFLICT);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/nookbook/global/payload/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public enum ErrorCode {
INVALID_OPTIONAL_ISPRESENT(400, "E004", "ํ•ด๋‹น ๊ฐ’์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
INVALID_CHECK(400, "E005", "ํ•ด๋‹น ๊ฐ’์ด ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."),
INVALID_AUTHENTICATION(400, "E006", "์ž˜๋ชป๋œ ์ธ์ฆ์ž…๋‹ˆ๋‹ค."),
INVALID_TOKEN(400, "E007", "์ž˜๋ชป๋œ ํ† ํฐ์ž…๋‹ˆ๋‹ค.");
INVALID_TOKEN(400, "E007", "์ž˜๋ชป๋œ ํ† ํฐ์ž…๋‹ˆ๋‹ค."),
NOT_FOUND(404, "E008", "ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
DUPLICATE_ERROR(409, "E009", "์ค‘๋ณต๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.");

private final String code;
private final String message;
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/com/nookbook/global/payload/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
package com.nookbook.global.payload;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.springframework.validation.FieldError;
import lombok.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ErrorResponse {


private String message;
private int status;
private String code;


@Builder
private ErrorResponse(final ErrorCode code) {
this.status = code.getStatus();
this.message = code.getMessage();
this.code = code.getCode();
}
public ErrorResponse(final ErrorCode code, final String message) {

private ErrorResponse(final ErrorCode code, final String message) {
this.status = code.getStatus();
this.message = message;
this.code = code.getCode();

}

public static ErrorResponse of(final ErrorCode code) {
return new ErrorResponse(code);
}

public static ErrorResponse of(final ErrorCode code, final String message) {
return new ErrorResponse(code, message);

Expand Down

0 comments on commit a3059c0

Please sign in to comment.