fix: 403 handler, data integrity handler, phone column size

This commit is contained in:
pray4skylark
2026-06-12 10:28:12 +09:00
parent 0d538d66f0
commit 65c123fec9
4 changed files with 161 additions and 1 deletions
@@ -3,7 +3,10 @@ package com.srsystem.exception;
import com.srsystem.dto.ApiResponse;
import jakarta.persistence.OptimisticLockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@@ -40,6 +43,21 @@ public class GlobalExceptionHandler {
.body(ApiResponse.error(ErrorCode.SYSTEM_CONCURRENCY.getMessage()));
}
@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ApiResponse<Void>> handleAccessDenied() {
return ResponseEntity
.status(HttpStatus.FORBIDDEN)
.body(ApiResponse.error("접근 권한이 없습니다"));
}
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<ApiResponse<Void>> handleDataIntegrity(DataIntegrityViolationException ex) {
log.warn("Data integrity violation", ex);
return ResponseEntity
.badRequest()
.body(ApiResponse.error("데이터 중복 또는 제약 조건 위반입니다"));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<Void>> handleGenericException(Exception ex) {
log.error("Unexpected exception occurred", ex);
@@ -10,6 +10,7 @@ import com.srsystem.entity.enums.EmpStatus;
import com.srsystem.entity.enums.RoleCode;
import com.srsystem.exception.BusinessException;
import com.srsystem.exception.ErrorCode;
import org.springframework.dao.DataIntegrityViolationException;
import com.srsystem.repository.DispatchHistoryRepository;
import com.srsystem.repository.EmployeeEmergencyContactRepository;
import com.srsystem.repository.EmployeeRepository;
@@ -90,7 +91,11 @@ public class EmployeeService {
if (employee.getDispatchStatus() == null) employee.setDispatchStatus(DispatchStatus.WAITING);
employee.setPassword(passwordEncoder.encode(employee.getPassword()));
return employeeRepository.save(employee);
try {
return employeeRepository.save(employee);
} catch (DataIntegrityViolationException e) {
throw new BusinessException(ErrorCode.DUPLICATE_LOGIN_ID);
}
}
@Transactional
@@ -0,0 +1 @@
ALTER TABLE tb_employee ALTER COLUMN phone TYPE VARCHAR(255);