Skip to content

Commit

Permalink
refoctor: category advice contoller 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
kihwankim committed Jan 31, 2022
1 parent 9fe22fa commit 81dd5e8
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.yapp.sharefood.category.advice;

import com.yapp.sharefood.category.exception.CategoryNotFoundException;
import lombok.RequiredArgsConstructor;
import com.yapp.sharefood.common.error.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CategoryAdviceController {
@ExceptionHandler(CategoryNotFoundException.class)
protected ResponseEntity<String> handlerCategoryNotFoundException(final CategoryNotFoundException exception) {
protected ResponseEntity<ErrorResponse> handlerCategoryNotFoundException(final CategoryNotFoundException exception) {
log.info("CategoryNotFoundException: {}", exception.getMessage(), exception);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(exception.getMessage());
return ErrorResponse.toResponseEntity(HttpStatus.NOT_FOUND, exception.getMessage());
}
}

0 comments on commit 81dd5e8

Please sign in to comment.