Skip to content

Commit

Permalink
feat #15 : Global Exception 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
JJONSOO committed Jul 31, 2023
1 parent 03c7613 commit 3b07705
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.issuetrackermax.common.exception;

import org.springframework.http.HttpStatus;

import lombok.Builder;
import lombok.Getter;

@Getter
public class ApiException extends RuntimeException {
private final HttpStatus httpStatus;
private final String message;

@Builder
private ApiException(HttpStatus httpStatus, String message) {
this.httpStatus = httpStatus;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.issuetrackermax.common.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.issuetrackermax.controller.ApiResponse;

@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(ApiException.class)
public ApiResponse<ErrorResponse> apiExceptionHandler(ApiException e) {
ErrorCode errorCode = new ErrorCode(e.getHttpStatus().value(), e.getMessage());
return ApiResponse.exception(ErrorResponse.exception(errorCode));
}
}

0 comments on commit 3b07705

Please sign in to comment.