Skip to content

Commit

Permalink
ID-361 Explicitly capture exceptions with sentry. (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-in-a-Jar authored Mar 3, 2023
1 parent 1693c93 commit f5300fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/scala/thurloe/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object Main extends App {
sys.env.get("SENTRY_DSN").foreach { dsn =>
val options = new SentryOptions()
options.setDsn(dsn)
Sentry.init()
options.setEnvironment(sys.env.getOrElse("SENTRY_ENVIRONMENT", "unknown"))
Sentry.init(options)
}

// We need an ActorSystem to host our application in
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/thurloe/service/ThurloeService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import akka.http.scaladsl.model.{ContentTypes, HttpEntity, StatusCodes}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import com.typesafe.scalalogging.LazyLogging
import io.sentry.Sentry
import spray.json._
import thurloe.database.DatabaseOperation.DatabaseOperation
import thurloe.database.{DataAccess, DatabaseOperation, KeyNotFoundException}
Expand Down Expand Up @@ -62,6 +63,7 @@ trait ThurloeService extends LazyLogging {

private def handleError(e: Throwable) =
extract(_.request) { request =>
Sentry.captureException(e)
logger.error(s"error handling request: ${request.method} ${request.uri}", e)
complete(StatusCodes.InternalServerError, s"$Interjection $e")
}
Expand Down

0 comments on commit f5300fe

Please sign in to comment.