Skip to content

Commit

Permalink
Fix handling error for known http statuses
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Nov 30, 2024
1 parent c8bb7b0 commit 7c1c34a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/groovy/io/seqera/wave/ErrorHandler.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,8 +56,9 @@ class ErrorHandler {
def <T> HttpResponse<T> handle(HttpRequest httpRequest, Throwable t, Mapper<T> 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
Expand All @@ -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
Expand Down

0 comments on commit 7c1c34a

Please sign in to comment.