Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 1.09 KB

service.md

File metadata and controls

27 lines (20 loc) · 1.09 KB

Exception Handling

Service layer의 exception handling은 GlobalExceptionHandler를 통해 관리

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(AuthException.class)
    public ResponseEntity<ApiResponseDto<Object>> handleFriendException(AuthException e) {
        return ResponseEntity.status(e.getStatus()).body(ApiResponseDto.error(e.getStatus(), e.getMessage()));
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<ApiResponseDto<Object>> handleFriendException(BusinessException e) {
        return ResponseEntity.status(e.getStatus()).body(ApiResponseDto.error(e.getStatus(), e.getMessage()));
    }

}

ErrorCodeException 정의 후 아래 예시와 같이 service layer에서 예외 생성

throw new AuthException(AuthErrorCode.OAUTH_PROCESS_ERROR);
throw new BusinessException(FriendErrorCode.RECEIPT_ALREADY_EXISTS);