Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Sentry, Spring Boot 연동 #56

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ dependencies {

// Social Login
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0'

// Sentry
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:7.1.0'
implementation 'io.sentry:sentry-logback:7.1.0'
}

tasks.named('bootBuildImage') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.pingle.pingleserver.exception;

import io.sentry.Sentry;
import lombok.extern.slf4j.Slf4j;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.type.ErrorMessage;
Expand All @@ -21,55 +22,63 @@ public class GlobalExceptionHandler {
@ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseEntity<ApiResponse<?>> handlerMethodArgumentNotValidException(Exception e) {
log.error("handlerMethodArgumentNotValidException() in GlobalExceptionHandler throw MethodArgumentNotValidException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.fail(ErrorMessage.BAD_REQUEST));
}

@ExceptionHandler(value={MethodArgumentTypeMismatchException.class})
public ResponseEntity<ApiResponse<?>> handlerMethodArgumentTypeMismatchException(Exception e) {
log.error("handlerMethodArgumentTypeMismatchException() in GlobalExceptionHandler throw MethodArgumentTypeMismatchException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.fail(ErrorMessage.BAD_REQUEST));
}

@ExceptionHandler(value = {MissingRequestHeaderException.class})
public ResponseEntity<ApiResponse<?>> handlerMissingRequestHeaderException(Exception e) {
log.error("handlerMissingRequestHeaderException() in GlobalExceptionHandler throw MissingRequestHeaderException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.fail(ErrorMessage.MISSING_REQUIRED_HEADER));
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ApiResponse<?>> handleMessageNotReadableException(HttpMessageNotReadableException e) {
log.error("handleMessageNotReadableException() in GlobalExceptionHandler throw HttpMessageNotReadableException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.fail(ErrorMessage.BAD_REQUEST));
}

@ExceptionHandler(value = {NoHandlerFoundException.class})
public ResponseEntity<ApiResponse<?>> handleNoPageFoundException(Exception e) {
log.error("handleNoPageFoundException() in GlobalExceptionHandler throw NoHandlerFoundException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(ApiResponse.fail(ErrorMessage.NOT_FOUND_END_POINT));
}

@ExceptionHandler(value = {HttpRequestMethodNotSupportedException.class})
public ResponseEntity<ApiResponse<?>> handleMethodNotSupportedException(Exception e) {
log.error("handleMethodNotSupportedException() in GlobalExceptionHandler throw HttpRequestMethodNotSupportedException : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED)
.body(ApiResponse.fail(ErrorMessage.METHOD_NOT_ALLOWED));
}

@ExceptionHandler(CustomException.class)
public ResponseEntity<ApiResponse<?>> handleCustomException(CustomException e) {
log.error("handleException() in GlobalExceptionHandler throw BusinessException : {}", e.getErrorMessage());
//log.error("handleException() in GlobalExceptionHandler throw BusinessException : {}", e.getErrorMessage());
Sentry.captureException(e);
return ResponseEntity.status(e.getHttpStatusCode())
.body(ApiResponse.fail(e.getErrorMessage()));
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<?>> handlerException(Exception e) {
log.error("handlerException() in GlobalExceptionHandler throw Exception : {}", e.getMessage());
Sentry.captureException(e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.fail(ErrorMessage.INTERNAL_SERVER_ERROR));
}
Expand Down