Skip to content

Commit

Permalink
Allow to receive error code not defined in the lwm2m spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 10, 2017
1 parent 2f597fb commit 3cab54d
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,67 +43,60 @@ public LwM2mClientResponseBuilder(Response coapResponse) {

@Override
public void visit(RegisterRequest request) {
switch (coapResponse.getCode()) {
case CREATED:
lwM2mresponse = RegisterResponse.success(coapResponse.getOptions().getLocationString());
break;
case BAD_REQUEST:
case FORBIDDEN:
case INTERNAL_SERVER_ERROR:
if (coapResponse.isError()) {
// handle error response:
lwM2mresponse = new RegisterResponse(toLwM2mResponseCode(coapResponse.getCode()), null,
coapResponse.getPayloadString());
break;
default:
} else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CREATED) {
// handle success response:
lwM2mresponse = RegisterResponse.success(coapResponse.getOptions().getLocationString());
} else {
// handle unexpected response:
handleUnexpectedResponseCode(request, coapResponse);
}
}

@Override
public void visit(DeregisterRequest request) {
switch (coapResponse.getCode()) {
case DELETED:
lwM2mresponse = DeregisterResponse.success();
break;
case BAD_REQUEST:
case NOT_FOUND:
case INTERNAL_SERVER_ERROR:
if (coapResponse.isError()) {
// handle error response:
lwM2mresponse = new DeregisterResponse(toLwM2mResponseCode(coapResponse.getCode()),
coapResponse.getPayloadString());
break;
default:
} else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.DELETED) {
// handle success response:
lwM2mresponse = DeregisterResponse.success();
} else {
// handle unexpected response:
handleUnexpectedResponseCode(request, coapResponse);
}
}

@Override
public void visit(UpdateRequest request) {
switch (coapResponse.getCode()) {
case CHANGED:
lwM2mresponse = UpdateResponse.success();
break;
case BAD_REQUEST:
case NOT_FOUND:
case INTERNAL_SERVER_ERROR:
if (coapResponse.isError()) {
// handle error response:
lwM2mresponse = new UpdateResponse(toLwM2mResponseCode(coapResponse.getCode()),
coapResponse.getPayloadString());
break;
default:
} else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CHANGED) {
// handle success response:
lwM2mresponse = UpdateResponse.success();
} else {
// handle unexpected response:
handleUnexpectedResponseCode(request, coapResponse);
}
}

@Override
public void visit(BootstrapRequest request) {
switch (coapResponse.getCode()) {
case CHANGED:
lwM2mresponse = BootstrapResponse.success();
break;
case BAD_REQUEST:
case INTERNAL_SERVER_ERROR:
if (coapResponse.isError()) {
// handle error response:
lwM2mresponse = new BootstrapResponse(toLwM2mResponseCode(coapResponse.getCode()),
coapResponse.getPayloadString());
break;
default:
} else if (coapResponse.getCode() == org.eclipse.californium.core.coap.CoAP.ResponseCode.CHANGED) {
// handle success response:
lwM2mresponse = BootstrapResponse.success();
} else {
// handle unexpected response:
handleUnexpectedResponseCode(request, coapResponse);
}
}
Expand Down
Loading

0 comments on commit 3cab54d

Please sign in to comment.