Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-315] ControllerAdvice Sentry 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
rilac1 committed Apr 23, 2024
1 parent 676b1dc commit 8096966
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.studentcenter.weave.bootstrap.common.exception

import com.studentcenter.weave.support.common.exception.SystemException
import io.github.oshai.kotlinlogging.KotlinLogging
import io.sentry.Sentry
import io.swagger.v3.oas.annotations.Hidden
import jakarta.servlet.http.HttpServletRequest
import org.springframework.core.Ordered
Expand Down Expand Up @@ -46,6 +47,12 @@ class UnknownExceptionHandler {
): ErrorResponse {
logger.error { e.stackTraceToString() }

Sentry.captureException(e) { scope ->
scope.setExtra("method", request.method)
scope.setExtra("requestURI", request.requestURI)
scope.setExtra("queryString", request.queryString?.let { "?$it" } ?: "")
scope.setExtra("clientIp", request.getHeader("X-Forwarded-For") ?: request.remoteAddr)
}
return ErrorResponse(
exceptionCode = SystemException.InternalServerError().code,
message = "Internal Server Error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.studentcenter.weave.bootstrap.common.exception

import com.studentcenter.weave.support.common.exception.CustomException
import com.studentcenter.weave.support.common.exception.SystemException
import io.sentry.Sentry
import org.springframework.messaging.handler.annotation.MessageExceptionHandler
import org.springframework.web.bind.annotation.ControllerAdvice

Expand All @@ -26,6 +27,7 @@ class WebSocketExceptionHandler {

@MessageExceptionHandler(Exception::class)
fun handleException(exception: Exception): ErrorResponse {
Sentry.captureException(exception)
return ErrorResponse(
exceptionCode = SystemException.InternalServerError().code,
message = exception.message ?: "Internal server error"
Expand Down

0 comments on commit 8096966

Please sign in to comment.