Skip to content

Commit f0ea6f9

Browse files
committed
Improve network error messages by unwrapping cause chain
IOException.getMessage() can be null when the actual error is in getCause(). Now shows the cause class and message for better debugging.
1 parent 671e50c commit f0ea6f9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/dev/peekapi/PeekApiClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ private void send(List<RequestEvent> events) throws SendException {
399399
} catch (SendException e) {
400400
throw e;
401401
} catch (java.io.IOException e) {
402-
throw new SendException("Network error: " + e.getMessage(), true);
402+
String msg = e.getMessage();
403+
if (msg == null && e.getCause() != null) {
404+
msg = e.getCause().getClass().getSimpleName() + ": " + e.getCause().getMessage();
405+
}
406+
throw new SendException("Network error: " + msg, true);
403407
} catch (InterruptedException e) {
404408
Thread.currentThread().interrupt();
405409
throw new SendException("Request interrupted", true);

0 commit comments

Comments
 (0)