Skip to content

Commit 19b6af4

Browse files
committed
Pass internal errors back as the cause of a ProxerException
1 parent a660904 commit 19b6af4

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

library/src/main/java/me/proxer/library/api/ProxerCall.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ private T processResponse(@NotNull final Response<ProxerResponse<T>> response) t
133133

134134
private ProxerException processNonProxerError(@NotNull final Throwable error) {
135135
if (error instanceof SocketTimeoutException) {
136-
return new ProxerException(ProxerException.ErrorType.TIMEOUT);
136+
return new ProxerException(ProxerException.ErrorType.TIMEOUT, error);
137137
} else if (error instanceof IOException) {
138-
return new ProxerException(ProxerException.ErrorType.IO);
138+
return new ProxerException(ProxerException.ErrorType.IO, error);
139139
} else if (error instanceof JsonDataException) {
140-
return new ProxerException(ProxerException.ErrorType.PARSING);
140+
return new ProxerException(ProxerException.ErrorType.PARSING, error);
141141
} else {
142-
return new ProxerException(ProxerException.ErrorType.UNKNOWN);
142+
return new ProxerException(ProxerException.ErrorType.UNKNOWN, error);
143143
}
144144
}
145145
}

library/src/main/java/me/proxer/library/api/ProxerException.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public final class ProxerException extends Exception {
3434
@Getter(onMethod = @__({@Override, @Nullable}))
3535
private final String message;
3636

37+
/**
38+
* Constructs an instance from the passed {@code error}, {@code serverError}, {@code message} and {@code cause}.
39+
*/
40+
public ProxerException(@NotNull final ErrorType errorType, @Nullable final ServerErrorType serverErrorType,
41+
@Nullable final String message, @Nullable Throwable cause) {
42+
super(cause);
43+
44+
this.errorType = errorType;
45+
this.serverErrorType = serverErrorType;
46+
this.message = message;
47+
}
48+
3749
/**
3850
* Constructs an instance from the passed {@code error}, {@code serverError} and {@code message}.
3951
*/
@@ -56,6 +68,19 @@ public ProxerException(@NotNull final ErrorType errorType, @Nullable final Integ
5668
this.message = message;
5769
}
5870

71+
/**
72+
* Constructs an instance from the passed {@code error} and {@code cause}.
73+
* <p>
74+
* {@link #getServerErrorType()} and {@link #getMessage()} will return null.
75+
*/
76+
public ProxerException(@NotNull final ErrorType errorType, @Nullable Throwable cause) {
77+
super(cause);
78+
79+
this.errorType = errorType;
80+
this.serverErrorType = null;
81+
this.message = null;
82+
}
83+
5984
/**
6085
* Constructs an instance from the passed {@code error}.
6186
* <p>

0 commit comments

Comments
 (0)