From d60589193c2d7aabedd94937c78ba84a9b136280 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Mon, 29 Apr 2024 12:54:09 +0200 Subject: [PATCH] Improve error reporting Signed-off-by: Paolo Di Tommaso --- .../wave/exception/HttpResponseException.groovy | 6 ++---- .../tower/client/connector/TowerConnector.groovy | 16 +++++++++------- .../groovy/io/seqera/wave/util/RegHelper.groovy | 4 +++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/exception/HttpResponseException.groovy b/src/main/groovy/io/seqera/wave/exception/HttpResponseException.groovy index 005fb81b3..17a16ea5a 100644 --- a/src/main/groovy/io/seqera/wave/exception/HttpResponseException.groovy +++ b/src/main/groovy/io/seqera/wave/exception/HttpResponseException.groovy @@ -54,10 +54,8 @@ class HttpResponseException extends WaveException implements HttpError { @Override String getMessage() { def result = super.getMessage() - if( statusCode!=null ) - result += " - HTTP status=${statusCode.code}" - if( response ) - result += " - response=$response" + result += " - HTTP status=${statusCode?.code ?: '-'}" + result += " - response=${response ?: '-'}" return result } } diff --git a/src/main/groovy/io/seqera/wave/tower/client/connector/TowerConnector.groovy b/src/main/groovy/io/seqera/wave/tower/client/connector/TowerConnector.groovy index ec0b44518..41205bc69 100644 --- a/src/main/groovy/io/seqera/wave/tower/client/connector/TowerConnector.groovy +++ b/src/main/groovy/io/seqera/wave/tower/client/connector/TowerConnector.groovy @@ -130,9 +130,7 @@ abstract class TowerConnector { default: def body = resp.body def msg = "Unexpected status code ${resp.status} while accessing Tower resource: $uri" - if (body) - msg += " - response: ${body}" - throw new HttpResponseException(resp.status, msg) + throw new HttpResponseException(resp.status, msg, body) } } .exceptionallyCompose((Throwable err)-> { @@ -239,12 +237,16 @@ abstract class TowerConnector { return sendAsync(endpoint, request) .thenApply { resp -> - log.trace "Tower Refresh '$uri' response; msgId=${msgId}\n- status : ${resp.status}\n- headers: ${RegHelper.dumpHeaders(resp.headers)}\n- content: ${resp.body}" - if ( !resp || resp.status >= 400 ) { - def msg = "Unexpected Tower response refreshing JWT token" - if( resp ) msg += " [${resp.status}]" + if( resp==null ) + throw new HttpResponseException(500, "Missing Tower response refreshing JWT token: ${request.uri}") + if ( resp.status >= 400 ) { + log.debug "Tower Refresh '$uri' response; msgId=${msgId}\n- status : ${resp.status}\n- headers: ${RegHelper.dumpHeaders(resp.headers)}\n- content: ${resp.body}" + final msg = "Unexpected Tower response refreshing JWT token: ${request.uri}" throw new HttpResponseException(resp.status, msg, resp.body) } + else if( log.isTraceEnabled() ) { + log.trace "Tower Refresh '$uri' response; msgId=${msgId}\n- status : ${resp.status}\n- headers: ${RegHelper.dumpHeaders(resp.headers)}\n- content: ${resp.body}" + } final cookies = resp.headers?['set-cookie'] ?: [] final jwtAuth = parseTokens(cookies, refreshToken) return jwtAuthStore.putJwtAuth(endpoint, originalAuthToken, jwtAuth) diff --git a/src/main/groovy/io/seqera/wave/util/RegHelper.groovy b/src/main/groovy/io/seqera/wave/util/RegHelper.groovy index cb9cf29e9..2f8e4f2a1 100644 --- a/src/main/groovy/io/seqera/wave/util/RegHelper.groovy +++ b/src/main/groovy/io/seqera/wave/util/RegHelper.groovy @@ -110,7 +110,9 @@ class RegHelper { } static String dumpHeaders(Map> headers) { - def result = new StringBuilder() + if( !headers ) + null + final result = new StringBuilder() for( Map.Entry> entry : headers ) { for( String val : entry.value ) result.append("\n $entry.key=$val")