본문 바로가기
[패스트캠퍼스] Spring

패스트캠퍼스 챌린지 29일차

by 엑츄얼리 2022. 2. 21.

Part 1. Spring Framework

 Ch 04. 예외처리

  01. 글로벌 예외처리 기법_01

  - 내부적인 오류를 처리할 때는 한번에 직관적으로 처리하는게 좋음

.
.
.
@DeleteMapping("/developer/{memberId}")
public DeveloperDetailDto deleteDeveloper(
        @PathVariable String memberId
) {
    return dMakerService.deleteDeveloper(memberId);
}

@ResponseStatus(value = HttpStatus.CONFLICT)
@ExceptionHandler(DMakerException.class)
public DMakerErrorResponse handleException(DMakerException e,
                                           HttpServletRequest request
) {
    log.error("errorCode : {}, url: {}, message : {}", e.getDMakerErrorCode(), e.getDetailMessage());

    return DMakerErrorResponse.builder()
            .errorCode(e.getDMakerErrorCode())
            .errorMessage(e.getDetailMessage())

            .build();
}

<DMakerController.java>

 

import exception.DMakerErrorCode;
import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder

public class DMakerErrorResponse {
    private DMakerErrorCode errorCode;
    private String errorMessage;
}

<DMakerErrorResponse.java>

 

 

-----------------------------------------------------------------------------------------------------------------------------------------

 

https://bit.ly/37BpXic

댓글