Skip to content

Commit

Permalink
Improve error reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Apr 29, 2024
1 parent 1c3d08d commit d605891
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)-> {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/main/groovy/io/seqera/wave/util/RegHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class RegHelper {
}

static String dumpHeaders(Map<String, List<String>> headers) {
def result = new StringBuilder()
if( !headers )
null
final result = new StringBuilder()
for( Map.Entry<String,List<String>> entry : headers ) {
for( String val : entry.value )
result.append("\n $entry.key=$val")
Expand Down

0 comments on commit d605891

Please sign in to comment.