Skip to content

Commit

Permalink
Merge pull request #64 from Central-MakeUs/dev
Browse files Browse the repository at this point in the history
fix: 리다이렉트 롤백
  • Loading branch information
KarmaPol authored Apr 2, 2024
2 parents 861663c + 284cecb commit 76ffee5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
129 changes: 68 additions & 61 deletions api/src/main/java/com/mm/api/exception/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.mm.api.exception;

import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import lombok.extern.slf4j.Slf4j;
import static com.mm.api.exception.ErrorCode.*;

import java.security.SignatureException;
import java.util.List;
import java.util.Objects;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -12,66 +15,70 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.security.SignatureException;
import java.util.List;
import java.util.Objects;

import static com.mm.api.exception.ErrorCode.*;
import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import io.sentry.Sentry;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ErrorResponse> handleAccessDeniedException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_DENIED.getErrorCode(), ACCESS_DENIED.getMessage());
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(errorResponse);
}

@ExceptionHandler(SignatureException.class)
public ResponseEntity<ErrorResponse> handleSignatureException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_MALFORMED.getErrorCode(), ACCESS_TOKEN_MALFORMED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(MalformedJwtException.class)
public ResponseEntity<ErrorResponse> handleMalformedJwtException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_MALFORMED.getErrorCode(), ACCESS_TOKEN_MALFORMED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(ExpiredJwtException.class)
public ResponseEntity<ErrorResponse> handleExpiredJwtException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_EXPIRED.getErrorCode(), ACCESS_TOKEN_EXPIRED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(CustomException.class)
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
log.info(">>>>> CustomException occurred!! {}", e);

ErrorResponse errorResponse = new ErrorResponse(e.getCode().getErrorCode(), e.getMessage());
return ResponseEntity.status(e.getCode().getStatus()).body(errorResponse);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleMethodArgumentException(MethodArgumentNotValidException e) {
log.info(">>>>> MethodArgumentNotValidException occurred!! {}", e);

BindingResult bindingResult = e.getBindingResult();
String errorMessage = Objects.requireNonNull(bindingResult.getFieldError())
.getDefaultMessage();

List<FieldError> fieldErrors = bindingResult.getFieldErrors();
ErrorResponse errorResponse = new ErrorResponse(ErrorCode.VALIDATION_FAILED.getErrorCode(), errorMessage);
fieldErrors.forEach(error -> errorResponse.addValidation(error.getField(), error.getDefaultMessage()));
return ResponseEntity.status(e.getStatusCode()).body(errorResponse);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
log.info(">>>>> Internal Server error occurred!! {}", e);

ErrorResponse errorResponse = new ErrorResponse("500/0001", e.getMessage());
return ResponseEntity.internalServerError().body(errorResponse);
}
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ErrorResponse> handleAccessDeniedException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_DENIED.getErrorCode(), ACCESS_DENIED.getMessage());
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(errorResponse);
}

@ExceptionHandler(SignatureException.class)
public ResponseEntity<ErrorResponse> handleSignatureException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_MALFORMED.getErrorCode(),
ACCESS_TOKEN_MALFORMED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(MalformedJwtException.class)
public ResponseEntity<ErrorResponse> handleMalformedJwtException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_MALFORMED.getErrorCode(),
ACCESS_TOKEN_MALFORMED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(ExpiredJwtException.class)
public ResponseEntity<ErrorResponse> handleExpiredJwtException() {
ErrorResponse errorResponse = new ErrorResponse(ACCESS_TOKEN_EXPIRED.getErrorCode(),
ACCESS_TOKEN_EXPIRED.getMessage());
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorResponse);
}

@ExceptionHandler(CustomException.class)
public ResponseEntity<ErrorResponse> handleCustomException(CustomException e) {
log.info(">>>>> CustomException occurred!! {}", e);

ErrorResponse errorResponse = new ErrorResponse(e.getCode().getErrorCode(), e.getMessage());
return ResponseEntity.status(e.getCode().getStatus()).body(errorResponse);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleMethodArgumentException(MethodArgumentNotValidException e) {
log.info(">>>>> MethodArgumentNotValidException occurred!! {}", e);

BindingResult bindingResult = e.getBindingResult();
String errorMessage = Objects.requireNonNull(bindingResult.getFieldError())
.getDefaultMessage();

List<FieldError> fieldErrors = bindingResult.getFieldErrors();
ErrorResponse errorResponse = new ErrorResponse(ErrorCode.VALIDATION_FAILED.getErrorCode(), errorMessage);
fieldErrors.forEach(error -> errorResponse.addValidation(error.getField(), error.getDefaultMessage()));
return ResponseEntity.status(e.getStatusCode()).body(errorResponse);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
log.info(">>>>> Internal Server error occurred!! {}", e);

Sentry.captureException(e);

ErrorResponse errorResponse = new ErrorResponse("500/0001", e.getMessage());
return ResponseEntity.internalServerError().body(errorResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Item getZigZagItemByCrawler(String redirectUrl) {
Item item = Item.builder()
.price(response.finalPrice())
.title(response.name())
.redirectUrl(response.pageUrl())
.redirectUrl(redirectUrl)
.categoryType(categoryType)
.refund(getRefundPrice(response.finalPrice(), categoryType.getRefundPercent()))
.thumbnailUrl(response.thumbnailUrl())
Expand Down

0 comments on commit 76ffee5

Please sign in to comment.