Skip to content

Commit 6886ee2

Browse files
author
Johan Walles
authored
Add path and status code to exception message (#75)
Before this change, if you got a RequestNotOkException in a log file, it wasn't possible to see which request it was that failed. With this change in place, the path and status code of the exception are prepended to the exception message, and any logged exceptions will contain information on what operation it was that failed.
1 parent 12f5323 commit 6886ee2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/com/spotify/github/v3/exceptions/RequestNotOkException.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public class RequestNotOkException extends GithubException {
4040
private final int statusCode;
4141
private final String path;
4242

43+
private static String decoratedMessage(final String path, final int statusCode, final String msg) {
44+
return String.format("%s %d: %s", path, statusCode, msg);
45+
}
46+
4347
/**
4448
* Response to request came back with non-2xx status code
4549
*
@@ -48,7 +52,7 @@ public class RequestNotOkException extends GithubException {
4852
* @param msg response body
4953
*/
5054
public RequestNotOkException(final String path, final int statusCode, final String msg) {
51-
super(msg);
55+
super(decoratedMessage(path, statusCode, msg));
5256
this.statusCode = statusCode;
5357
this.path = path;
5458
}
@@ -63,7 +67,7 @@ public RequestNotOkException(final String path, final int statusCode, final Stri
6367
*/
6468
public RequestNotOkException(
6569
final String path, final int statusCode, final String msg, final Throwable cause) {
66-
super(msg, cause);
70+
super(decoratedMessage(path, statusCode, msg), cause);
6771
this.statusCode = statusCode;
6872
this.path = path;
6973
}

0 commit comments

Comments
 (0)