From 7c1c34a2b5b3937d4d388cdb883f904f1544a1f1 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Sat, 30 Nov 2024 09:48:08 +0100 Subject: [PATCH] Fix handling error for known http statuses Signed-off-by: Paolo Di Tommaso --- src/main/groovy/io/seqera/wave/ErrorHandler.groovy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/io/seqera/wave/ErrorHandler.groovy b/src/main/groovy/io/seqera/wave/ErrorHandler.groovy index 0d872918b..7999adfe9 100644 --- a/src/main/groovy/io/seqera/wave/ErrorHandler.groovy +++ b/src/main/groovy/io/seqera/wave/ErrorHandler.groovy @@ -24,6 +24,7 @@ import io.micronaut.http.HttpRequest import io.micronaut.http.HttpResponse import io.micronaut.http.HttpResponseFactory import io.micronaut.http.HttpStatus +import io.micronaut.http.exceptions.HttpStatusException import io.micronaut.security.authentication.AuthorizationException import io.seqera.wave.exception.BuildTimeoutException import io.seqera.wave.exception.DockerRegistryException @@ -55,8 +56,9 @@ class ErrorHandler { def HttpResponse handle(HttpRequest httpRequest, Throwable t, Mapper responseFactory) { final errId = LongRndKey.rndHex() final request = httpRequest?.toString() + final knownException = t instanceof WaveException || t instanceof HttpStatusException def msg = t.message - if( t instanceof WaveException && msg ) { + if( knownException && msg ) { // the the error cause if( t.cause ) msg += " - Cause: ${t.cause.message ?: t.cause}".toString() // render the message for logging @@ -81,6 +83,13 @@ class ErrorHandler { log.error(render, t) } + if( t instanceof HttpStatusException ) { + final body = t.body.isPresent() ? t.body.get().toString() : t.message + return HttpResponse + .status(t.status) + .body((T)body) + } + if( t instanceof RegistryForwardException ) { // report this error as it has been returned by the target registry return HttpResponse