Skip to content

Commit

Permalink
Check reason string in MQTT5 samples (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfod authored Jan 8, 2025
1 parent 602121d commit 284eea0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
22 changes: 11 additions & 11 deletions samples/mqtt5/mqtt5_pubsub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ int main(int argc, char *argv[])
{
if (reasonCode > Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR)
{
fprintf(
stdout,
"MQTT5 Client Subscription failed with server error code: (%d)%s\n",
reasonCode,
suback->getReasonString()->c_str());
fprintf(stdout, "MQTT5 Client Subscription failed with server error code: %d\n", reasonCode);
if (suback->getReasonString().has_value())
{
fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str());
}
subscribeSuccess.set_value(false);
return;
}
Expand Down Expand Up @@ -185,13 +185,13 @@ int main(int argc, char *argv[])
}
else
{
fprintf(
stdout,
"PubACK reason code: %d : %s\n",
puback->getReasonCode(),
puback->getReasonString()->c_str());
fprintf(stdout, "PubACK reason code: %d\n", puback->getReasonCode());
if (puback->getReasonString().has_value())
{
fprintf(stdout, "\nError reason string: %s\n", puback->getReasonString()->c_str());
}
}
};
}
};

uint32_t publishedCount = 0;
Expand Down
21 changes: 12 additions & 9 deletions samples/mqtt5/mqtt5_shared_subscription/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ int main(int argc, char *argv[])
{
if (reasonCode >= Mqtt5::SubAckReasonCode::AWS_MQTT5_SARC_UNSPECIFIED_ERROR)
{
fprintf(
stdout,
"MQTT5 Client Subscription failed with server error code: (%d)%s\n",
reasonCode,
suback->getReasonString()->c_str());
fprintf(stdout, "MQTT5 Client Subscription failed with server error code: %d\n", reasonCode);
if (suback->getReasonString().has_value())
{
fprintf(stdout, "\tError reason string: %s\n", suback->getReasonString()->c_str());
}
subscribeSuccess.set_value(reasonCode);
return;
}
Expand Down Expand Up @@ -331,12 +331,15 @@ int main(int argc, char *argv[])
{
fprintf(
stdout,
"[%s] Publish failed. PubACK reason code: %d : %s\n",
"[%s] Publish failed. PubACK reason code: %d\n",
publisher->name.c_str(),
puback->getReasonCode(),
puback->getReasonString()->c_str());
puback->getReasonCode());
if (puback->getReasonString().has_value())
{
fprintf(stdout, "\nError reason string: %s\n", puback->getReasonString()->c_str());
}
}
};
}
};

uint64_t publishedCount = 0;
Expand Down

0 comments on commit 284eea0

Please sign in to comment.