From 937eecdafefaac6c8e7681205d5827fa46bb81f4 Mon Sep 17 00:00:00 2001 From: ruhan Date: Mon, 16 Mar 2026 10:56:53 +0800 Subject: [PATCH] Improve error messages in ErrorResponseExceptionMapper Replace generic "Unknown error" messages with detailed HTTP 500 error information including status codes, response headers, and status info. This helps with debugging when backend services fail by providing correlation IDs and other diagnostic information in the logs. Co-Authored-By: Claude Sonnet 4.5 --- .../client/ErrorResponseExceptionMapper.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/commonjava/service/promote/client/ErrorResponseExceptionMapper.java b/src/main/java/org/commonjava/service/promote/client/ErrorResponseExceptionMapper.java index fa7d86d..eb03db5 100644 --- a/src/main/java/org/commonjava/service/promote/client/ErrorResponseExceptionMapper.java +++ b/src/main/java/org/commonjava/service/promote/client/ErrorResponseExceptionMapper.java @@ -44,19 +44,34 @@ public RuntimeException toThrowable(Response response) { try (InputStream is = (InputStream) entity) { - throw new WebApplicationException(IOUtils.toString(is, Charset.defaultCharset())); + String errorBody = IOUtils.toString(is, Charset.defaultCharset()); + throw new WebApplicationException( + String.format("HTTP 500 error from service: %s", errorBody), + response.getStatus() + ); } catch (IOException e) { - throw new WebApplicationException("Unknown error, " + e.getMessage()); + throw new WebApplicationException( + String.format("HTTP 500 error from service (failed to read response body: %s). Headers: %s", + e.getMessage(), response.getHeaders()), + response.getStatus() + ); } } else { - throw new WebApplicationException(entity.toString()); + throw new WebApplicationException( + String.format("HTTP 500 error from service: %s", entity.toString()), + response.getStatus() + ); } } - throw new WebApplicationException("Unknown error"); + throw new WebApplicationException( + String.format("HTTP 500 error from service with no response body. Headers: %s, Status Info: %s", + response.getHeaders(), response.getStatusInfo()), + response.getStatus() + ); } return null; }