Skip to content

Commit

Permalink
[feat] create logging for sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
Parkjyun committed Jan 12, 2024
1 parent 2794491 commit e6fd4d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit e6fd4d3

Please sign in to comment.