Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check reason string in MQTT5 samples #772

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading