Skip to content

Commit

Permalink
ISPN-760 Provide meaningful Hot Rod exceptions to Java clients
Browse files Browse the repository at this point in the history
  • Loading branch information
maniksurtani committed Dec 2, 2010
1 parent 66d1bfd commit da3d372
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Expand Up @@ -7,8 +7,8 @@
* @since 4.1
*/
public class HotRodClientException extends RuntimeException {
private long messageId;
private int errorStatusCode;
private long messageId = -1;
private int errorStatusCode = -1;

public HotRodClientException() {
}
Expand All @@ -34,9 +34,12 @@ public HotRodClientException(String remoteMessage, long messageId, int errorStat

@Override
public String toString() {
return "HotRodServerException{" +
"messageId=" + messageId +
", errorStatusCode=" + errorStatusCode +
"} " + super.toString();
StringBuilder sb = new StringBuilder(getClass().getName());
sb.append(":");
if (messageId != -1) sb.append(" id [").append(messageId).append("]");
if (errorStatusCode != -1) sb.append(" code [").append(errorStatusCode).append("]");
String message = getLocalizedMessage();
if (message != null) sb.append(" ").append(message);
return sb.toString();
}
}
Expand Up @@ -7,4 +7,22 @@
* @since 4.1
*/
public class HotRodTimeoutException extends HotRodClientException {
public HotRodTimeoutException() {
}

public HotRodTimeoutException(String message) {
super(message);
}

public HotRodTimeoutException(Throwable cause) {
super(cause);
}

public HotRodTimeoutException(String message, Throwable cause) {
super(message, cause);
}

public HotRodTimeoutException(String remoteMessage, long messageId, int errorStatusCode) {
super(remoteMessage, messageId, errorStatusCode);
}
}
Expand Up @@ -129,10 +129,11 @@ protected void checkForErrorsInResponseStatus(short status, long messageId, Tran
throw new HotRodClientException(msgFromServer, messageId, status);
}
case HotRodConstants.COMMAND_TIMEOUT_STATUS: {
String msg = transport.readString();
if (log.isTraceEnabled()) {
log.trace("timeout message received from the server");
log.trace("Server-side timeout performing operation: " + msg);
}
throw new HotRodTimeoutException();
throw new HotRodTimeoutException(msg, messageId, status);
}
case HotRodConstants.NO_ERROR_STATUS:
case HotRodConstants.KEY_DOES_NOT_EXIST_STATUS:
Expand Down

0 comments on commit da3d372

Please sign in to comment.