If I want to catch all my exceptions and log them ...
# ktor
s
If I want to catch all my exceptions and log them to bugsnag, or Datadog, where is the best place to do that? I was considering the
StatusPages
plugin, using the
Throwable
catch all.
Copy code
install(StatusPages) {
            exception<Throwable> {
                call.respond(HttpStatusCode.InternalServerError)
            }
        }
r
We used this as well, but it doesn’t catch exceptions in plugins (the classical API at least, don’t know what happens with the new
createApplicationPlugin
API)
r
@Rescribet Can you create tickets for such plugins? It’s not an expected behaviour
r
@Rustam Siniukov Yes, I’ll see if I can make a repro first
🙏 1
s
@Rustam Siniukov So the approach I’m taking should be fine then?
r
Yes, it should work. Otherwise, please file a bug
r
@Rustam Siniukov The 2.0.0-beta-1 StatusPages does catch plugin exceptions, but doesn’t prevent later handlers from being called. Which can lead to unexpected behaviour. We currently do a manual check to see StatusPages was activated to work around this:
Copy code
if (call.attributes.contains(AttributeKey<Unit>("StatusPagesTriggered"))) {
  return@get
}
https://youtrack.jetbrains.com/issue/KTOR-3707
a
@Rescribet thank you. I confirm that it's a bug.
🐛 1