Skip to content

Commit

Permalink
Improve Cling error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Apr 19, 2019
1 parent 97225dd commit ee6b8b9
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
import org.fourthline.cling.model.message.control.IncomingActionResponseMessage;
import org.fourthline.cling.model.meta.RemoteService;
import org.fourthline.cling.protocol.sync.SendingAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ActionService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final RemoteService remoteService;
private final ControlPoint controlPoint;

Expand All @@ -46,10 +50,14 @@ public <T> T run(final ClingAction<T> action) {

final IncomingActionResponseMessage response = prot.getOutputMessage();
if (response == null) {
throw new ClingRouterException("Got null response for action " + actionInvocation);
final String message = "Got null response for action " + actionInvocation;
logger.error(message);
throw new ClingRouterException(message);
} else if (response.getOperation().isFailed()) {
throw new ClingOperationFailedException("Invocation " + actionInvocation + " failed with operation '"
+ response.getOperation() + "', body '" + response.getBodyString() + "'", response);
final String message = "Invocation " + actionInvocation + " failed with operation '"
+ response.getOperation() + "', body '" + response.getBodyString() + "'";
logger.error(message);
throw new ClingOperationFailedException(message, response);
}
return action.convert(actionInvocation);
}
Expand Down

0 comments on commit ee6b8b9

Please sign in to comment.