TA 역할 Spring 경계 smoke #7

Open
forge-bot wants to merge 9 commits from forge/role-ta-live-1522-001-attempt-3-run-12d03ada6afe into main
Showing only changes of commit a0b93636c9 - Show all commits

View file

@ -0,0 +1,37 @@
package com.klaroworks.runtime.exception;
import com.klaroworks.runtime.dto.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public ResponseEntity<ApiResponse<Void>> handleBusinessException(BusinessException ex) {
log.warn("Business exception: {}", ex.getErrorCode().getCode());
return ResponseEntity.status(ex.getErrorCode().getHttpStatus())
.body(ApiResponse.error(ex.getErrorCode()));
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ApiResponse<Void>> handleValidationException(MethodArgumentNotValidException ex) {
var errors = ex.getBindingResult().getFieldErrors().stream()
.collect(java.util.stream.Collectors.toMap(
e -> e.getField(), e -> e.getDefaultMessage()));
log.warn("Validation failed: {}", errors);
return ResponseEntity.badRequest()
.body(ApiResponse.error(ErrorCode.INVALID_REQUEST, errors));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<Void>> handleGenericException(Exception ex) {
log.error("Unexpected error", ex);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.error(ErrorCode.INTERNAL_SERVER_ERROR));
}
}