Skip to content

Commit

Permalink
#1123: Better Handle LinkParseException.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 28, 2021
1 parent 8cd61fe commit 0ed5fd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Expand Up @@ -145,7 +145,8 @@ protected void handleRegister(CoapExchange exchange, Request request) {
try {
objectLinks = linkParser.parse(request.getPayload());
} catch (LinkParseException e) {
throw new IllegalArgumentException(e);
handleInvalidRequest(exchange.advanced(), e.getMessage() != null ? e.getMessage() : "Invalid Links", e);
return;
}

Map<String, String> additionalParams = new HashMap<>();
Expand Down Expand Up @@ -223,7 +224,8 @@ protected void handleUpdate(CoapExchange exchange, Request request, String regis
try {
objectLinks = linkParser.parse(request.getPayload());
} catch (LinkParseException e) {
throw new IllegalArgumentException(e);
handleInvalidRequest(exchange.advanced(), e.getMessage() != null ? e.getMessage() : "Invalid Links", e);
return;
}
}
Request coapRequest = exchange.advanced().getRequest();
Expand Down
Expand Up @@ -144,7 +144,9 @@ public void visit(DiscoverRequest request) {
try {
links = linkParser.parse(coapResponse.getPayload());
} catch (LinkParseException e) {
throw new IllegalArgumentException(e);
throw new InvalidResponseException(e,
"Unable to decode response payload of request [%s] from client [%s]", request,
clientEndpoint);
}
}
lwM2mresponse = new DiscoverResponse(ResponseCode.CONTENT, links, null, coapResponse);
Expand Down Expand Up @@ -366,7 +368,9 @@ public void visit(BootstrapDiscoverRequest request) {
try {
links = linkParser.parse(coapResponse.getPayload());
} catch (LinkParseException e) {
throw new IllegalArgumentException(e);
throw new InvalidResponseException(e,
"Unable to decode response payload of request [%s] from client [%s]", request,
clientEndpoint);
}
}
lwM2mresponse = new BootstrapDiscoverResponse(ResponseCode.CONTENT, links, null, coapResponse);
Expand Down

0 comments on commit 0ed5fd3

Please sign in to comment.