Skip to content

Commit

Permalink
Use String.format like constructor for InvalidResponseException
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 12, 2017
1 parent 744150b commit c01624a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public T getResponse() {
}

private void handleUnexpectedResponseCode(LwM2mRequest<?> request, Response coapResponse) {
throw new InvalidResponseException(String.format("Server returned unexpected response code [%s] for [%s]",
coapResponse.getCode(), request));
throw new InvalidResponseException("Server returned unexpected response code [%s] for [%s]",
coapResponse.getCode(), request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ public class InvalidResponseException extends RuntimeException {

private static final long serialVersionUID = 1L;


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

public InvalidResponseException(String m, Object... args) {
super(String.format(m, args));
}

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

public InvalidResponseException(Throwable e, String m, Object... args) {
super(String.format(m, args), e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ private LwM2mNode decodeCoapResponse(LwM2mPath path, Response coapResponse, LwM2
String.format("Unable to decode response payload of request [%s] from client [%s] [payload:%s]",
request, endpoint, Hex.encodeHexString(payload)));
}
throw new InvalidResponseException(String.format(
"Unable to decode response payload of request [%s] from client [%s]", request, endpoint), e);
throw new InvalidResponseException(e, "Unable to decode response payload of request [%s] from client [%s]",
request, endpoint);
}
}

Expand All @@ -347,7 +347,7 @@ public T getResponse() {
}

private void handleUnexpectedResponseCode(String clientEndpoint, LwM2mRequest<?> request, Response coapResponse) {
throw new InvalidResponseException(String.format("Client [%s] returned unexpected response code [%s] for [%s]",
clientEndpoint, coapResponse.getCode(), request));
throw new InvalidResponseException("Client [%s] returned unexpected response code [%s] for [%s]",
clientEndpoint, coapResponse.getCode(), request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ private ObserveResponse createObserveResponse(Observation observation, LwM2mMode
// // We handle CONTENT and CHANGED response only
if (coapResponse.getCode() != CoAP.ResponseCode.CHANGED
&& coapResponse.getCode() != CoAP.ResponseCode.CONTENT) {
throw new InvalidResponseException(String.format("Unexpected response code [%s]", coapResponse.getCode()));
throw new InvalidResponseException("Unexpected response code [%s] for %s", coapResponse.getCode(),
observation);
}

// get content format
Expand Down Expand Up @@ -283,8 +284,8 @@ private ObserveResponse createObserveResponse(Observation observation, LwM2mMode
LOG.debug(String.format("Unable to decode notification payload [%s] of observation [%s] ",
Hex.encodeHexString(payload), observation), e);
}
throw new InvalidResponseException(
String.format("Unable to decode notification payload of observation [%s] ", observation), e);
throw new InvalidResponseException(e, "Unable to decode notification payload of observation [%s] ",
observation);
}
}
}

0 comments on commit c01624a

Please sign in to comment.