Skip to content

Commit

Permalink
fix(iot-dev): fix amqp exception logging to check for all exposed exc…
Browse files Browse the repository at this point in the history
…eptions
  • Loading branch information
timtay-microsoft committed Aug 30, 2018
1 parent f40cdb1 commit dd56417
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 14 deletions.
Expand Up @@ -1099,17 +1099,66 @@ private TransportException getTransportExceptionFromEvent(Event event)
{
TransportException transportException = new TransportException("Unknown transport exception occurred");
transportException.setRetryable(true);
if (event.getSender() != null && event.getSender().getRemoteCondition() != null && event.getSender().getRemoteCondition().getCondition() != null)

String error = "";
String errorDescription = "";

String senderError = event.getSender() != null && event.getSender().getRemoteCondition() != null && event.getSender().getRemoteCondition().getCondition() != null ? event.getSender().getRemoteCondition().getCondition().toString() : "";
String receiverError = event.getReceiver() != null && event.getReceiver().getRemoteCondition() != null && event.getReceiver().getRemoteCondition().getCondition() != null ? event.getReceiver().getRemoteCondition().getCondition().toString() : "";
String sessionError = event.getSession() != null && event.getSession().getRemoteCondition() != null && event.getSession().getRemoteCondition().getCondition() != null ? event.getSession().getRemoteCondition().getCondition().toString() : "";
String connectionError = event.getConnection() != null && event.getConnection().getRemoteCondition() != null && event.getConnection().getRemoteCondition().getCondition() != null ? event.getConnection().getRemoteCondition().getCondition().toString() : "";
String linkError = event.getLink() != null && event.getLink().getRemoteCondition() != null && event.getLink().getRemoteCondition().getCondition() != null ? event.getLink().getRemoteCondition().getCondition().toString() : "";
String transportError = event.getTransport() != null && event.getTransport().getRemoteCondition() != null && event.getTransport().getRemoteCondition().getCondition() != null ? event.getTransport().getRemoteCondition().getCondition().toString() : "";

String senderErrorDescription = event.getSender() != null && event.getSender().getRemoteCondition() != null && event.getSender().getRemoteCondition().getDescription() != null ? event.getSender().getRemoteCondition().getDescription() : "";
String receiverErrorDescription = event.getReceiver() != null && event.getReceiver().getRemoteCondition() != null && event.getReceiver().getRemoteCondition().getDescription() != null ? event.getReceiver().getRemoteCondition().getDescription() : "";
String sessionErrorDescription = event.getSession() != null && event.getSession().getRemoteCondition() != null && event.getSession().getRemoteCondition().getDescription() != null ? event.getSession().getRemoteCondition().getDescription() : "";
String connectionErrorDescription = event.getConnection() != null && event.getConnection().getRemoteCondition() != null && event.getConnection().getRemoteCondition().getDescription() != null ? event.getConnection().getRemoteCondition().getDescription() : "";
String linkErrorDescription = event.getLink() != null && event.getLink().getRemoteCondition() != null && event.getLink().getRemoteCondition().getDescription() != null ? event.getLink().getRemoteCondition().getDescription() : "";
String transportErrorDescription = event.getTransport() != null && event.getTransport().getRemoteCondition() != null && event.getTransport().getRemoteCondition().getDescription() != null ? event.getTransport().getRemoteCondition().getDescription() : "";

if (!senderError.isEmpty())
{
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_081: [If an exception can be found in the sender, this function shall return a the mapped amqp exception derived from that exception.]
error = senderError;
errorDescription = senderErrorDescription;
}
else if (!receiverError.isEmpty())
{
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_082: [If an exception can be found in the receiver, this function shall return a the mapped amqp exception derived from that exception.]
error = receiverError;
errorDescription = receiverErrorDescription;
}
else if (!sessionError.isEmpty())
{
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_083: [If an exception can be found in the session, this function shall return a the mapped amqp exception derived from that exception.]
error = sessionError;
errorDescription = sessionErrorDescription;
}
else if (!connectionError.isEmpty())
{
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_084: [If an exception can be found in the connection, this function shall return a the mapped amqp exception derived from that exception.]
error = connectionError;
errorDescription = connectionErrorDescription;
}
else if (!linkError.isEmpty())
{
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_085: [If an exception can be found in the link, this function shall return a the mapped amqp exception derived from that exception.]
error = linkError;
errorDescription = linkErrorDescription;
}
else if (!transportError.isEmpty())
{
String amqpErrorType = event.getSender().getRemoteCondition().getCondition().toString();
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_086: [If an exception can be found in the transport, this function shall return a the mapped amqp exception derived from that exception.]
error = transportError;
errorDescription = transportErrorDescription;
}

String errorDescription = "";
if (event.getSender().getRemoteCondition().getDescription() != null)
{
errorDescription = event.getSender().getRemoteCondition().getDescription();
}

transportException = AmqpsExceptionTranslator.convertToAmqpException(amqpErrorType, errorDescription);
// Codes_SRS_AMQPSIOTHUBCONNECTION_34_080: [If no exception can be found in the sender, receiver, session, connection, link, or transport, this function shall return a generic TransportException.]
if (!error.isEmpty())
{
transportException = AmqpsExceptionTranslator.convertToAmqpException(error, errorDescription);
}

return transportException;
Expand Down

0 comments on commit dd56417

Please sign in to comment.