feat: api wrapping

This commit is contained in:
2025-11-17 15:23:36 +09:00
parent c081892ae7
commit 57943ebed4
6 changed files with 40 additions and 6 deletions

View File

@@ -0,0 +1,24 @@
package com.kamco.cd.kamcoback.config;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import jakarta.persistence.EntityNotFoundException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@Order(value = 1)
@RestControllerAdvice
public class GlobalExceptionHandler {
// 로그인 정보가 잘못됐습니다 권한 없음
@org.springframework.web.bind.annotation.ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(EntityNotFoundException.class)
public ApiResponseDto<String> handlerEntityNotFoundException(EntityNotFoundException e) {
log.warn("[EntityNotFoundException] resource :{} ", e.getMessage());
String message = String.format("%s [%s]", e.getMessage(), e.getCause());
return ApiResponseDto.createException(ApiResponseDto.ApiResponseCode.NOT_FOUND, message);
}
}