Skip to content

인터페이스를 제공하는 ErrorCode는 유지보수 친화적인 핸들링 구조를 제공합니다.

Notifications You must be signed in to change notification settings

merge-simpson/letsdev-error-code-api

Repository files navigation

Download (Maven/Gradle)

Gradle Script (Kotlin)

repositories {
    maven { url = uri("https://jitpack.io") } // added
}

dependencies {
    implementation("com.github.merge-simpson:letsdev-error-code-api:0.2.0") // added
}

Features

이 라이브러리는 다음 기능을 제공합니다.
하위 섹션에서 더 구체적으로 소개합니다. (업데이트 예정)

  • 에러코드 (인터페이스)
  • 커스텀 예외
  • 예외 처리 시 연계할 동작을 지정할 수 있습니다.
에러코드 구현 용례
%%{init: {"theme": "forest", "themeVariables": {"fontFamily": "Comic Sans MS"}}}%%
classDiagram
%% class list
    class ErrorCode {
        <<interface>>
    }
    class BoardErrorCode {
        <<enumeration>>
    }
    class SignUpErrorCode {
        <<enumeration>>
    }

%% relationship
    ErrorCode <|.. BoardErrorCode : implements
    ErrorCode <|.. SignUpErrorCode : implements
Loading

Pure Java Error Code

  • BaseErrorCode <<interface>>
  • BaseCustomException <<exception>>
%%{init: {"theme": "forest", "themeVariables": {"fontFamily": "Comic Sans MS"}}}%%
classDiagram
%% 클래스 목록
    class BaseErrorCode {
        <<interface>>
        +name() String
        +message() String
        +statusCode() int
        +exception() RuntimeException
        +exception(Throwable) RuntimeException
        +exception(Runnable) RuntimeException
        +exception(Runnable, Throwable) RuntimeException
        +exception(Supplier&lt;Map&lt;...>>) RuntimeException
        +exception(Supplier&lt;Map&lt;...>>, Throwable) RuntimeException
    }

    class BaseCustomException {
        <<exception>>
        #errorCode: BaseErrorCode
        #action: Runnable
        #payloadSupplier: Supplier&lt;Map&lt;...>>
        $DefaultBaseErrorCodeHolder.INSTANCE : BaseErrorCode
        
        +getErrorCode() BaseErrorCode
        +executeOnError() void
        +getPayload() Map&lt;...>
        +getPayloadOrElse(Map&lt;...>) Map&lt;...>
        +getPayloadOrElseGet(() -> Map&lt;...>) Map&lt;...>
    }

%% 관계 표현
    BaseCustomException ..> BaseErrorCode : uses
Loading

BaseErrorCode

BaseErrorCode는 에러 코드를 대표하는 최상위 인터페이스로 설계하였습니다. 이 인터페이스를 구현하면 오류 메시지, 상태 코드 및 관련 예외, 연계되는 동작 등을 제공합니다.

메서드 목록

  • name(): 에러 코드의 이름을 반환합니다.

    참고 사항: enum 클래스에서 기본적으로 제공하는 함수이므로, enum에서 이 인터페이스를 구현 시 생략해도 됩니다.

  • message(): 오류 메시지를 반환합니다.
  • statusCode(): 상태 코드를 정수로 반환합니다. (이 클래스는 스프링에 독립적이기 때문에 정수를 반환합니다.)
  • exception(): 관련성이 높은 기본 예외를 반환합니다.
  • exception(Throwable): 관련성이 높은 기본 예외를 반환합니다. 이때, 이 오류를 야기한 오류를 스택에 담습니다.
  • exception(Runnable): 이 오류를 처리할 때 함께 수행할 동작을 전달하며, 예외를 반환합니다.
  • exception(Runnable, Throwable): 위 메서드와 거의 같은 역할을 수행하며, 동시에 이 오류를 야기한 오류를 스택에 담습니다.
  • exception(Supplier<Map<String, Object>>): 이 오류를 처리할 때 함께 수행할 동작이자 확장 멤버를 반환하는 함수를 전달하며, 예외를 반환합니다.
  • exception(Supplier<Map<String, Object>>, Throwable): 위 메서드와 거의 같은 역할을 수행하며, 동시에 이 오류를 야기한 오류를 스택에 담습니다.

BaseCustomException

주요 기능 요약

  • 에러 코드를 핸들링합니다.
  • 오류 처리 시 동반되는 동작을 관리합니다.
  • 오류 처리 시 추가되는 확장 멤버를 관리합니다.

생성자

메서드

Spring-Dependent Error Code

  • ErrorCode: <<interface>>
  • CustomException <<exception>>

위 목록을 사용하려면 다음 의존성을 포함해야 합니다.
버전은 자유롭게 선택하십시오.

Group Artifact ID Version
org.springframework spring-web any
  • 각 의존성 라이브러리에서 org.springframework.http.HttpStatus를 포함하거나 호환되는 버전이 필요합니다.

Generalization Relationship

%%{init: {"theme": "forest", "themeVariables": {"fontFamily": "Comic Sans MS"}}}%%
classDiagram
%% 클래스 목록
    class BaseErrorCode {
        <<interface>>
    }

    class BaseCustomException {
        <<exception>>
    }
    
    class ErrorCode {
        <<interface>>
        +httpStatus() HttpStatus
    }

    class CustomException {
        <<exception>>
    }

%% 관계 표현
    BaseErrorCode --|> ErrorCode
    BaseCustomException --|> CustomException
Loading

About

인터페이스를 제공하는 ErrorCode는 유지보수 친화적인 핸들링 구조를 제공합니다.

Topics

Resources

Stars

Watchers

Forks

Languages