Skip to content

Commit

Permalink
Added root failure handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Apr 29, 2024
1 parent a2017e5 commit 78cdf82
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class HealthVerticle(
val router = Router.router(vertx)
.errorHandler(404) { it.end("Could not find request ${it.request().path()} ${it.request()}") }

router.route()
.failureHandler {
if (it.failure() == null)
logger.warn("Unhandled error in health verticle ${it.statusCode()}")
else
logger.warn("Unhandled error in health verticle ${it.statusCode()}", it.failure())
}

val server = vertx.createHttpServer(options)
.requestHandler(router)
.exceptionHandler { logger.warn("Socket error", it) }
Expand Down Expand Up @@ -222,9 +230,12 @@ class HealthVerticle(
)
}

registry.logUnhealthy

when (status.healthy) {
true -> context.json(results).coAwait()
false -> context.response().setStatusCode(HttpResponseStatus.SERVICE_UNAVAILABLE.code()).end().coAwait()
false -> context.response().setStatusCode(HttpResponseStatus.SERVICE_UNAVAILABLE.code()).end()
.coAwait()
}
}
}
Expand Down

0 comments on commit 78cdf82

Please sign in to comment.