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

Fix for Issue #1768 #1770

Merged
merged 4 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions sdk/inc/azure/iot/az_iot_hub_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ typedef enum
AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_GET = 1,
AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_DESIRED_PROPERTIES = 2,
AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES = 3,
AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_ERROR = 4,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REQUEST_ERROR ?

} az_iot_hub_client_twin_response_type;

/**
Expand Down
5 changes: 5 additions & 0 deletions sdk/samples/iot/paho_iot_hub_pnp_component_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ static void handle_device_twin_message(
case AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES:
IOT_SAMPLE_LOG("Message Type: Reported Properties");
break;

// An error response.
case AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_ERROR:
IOT_SAMPLE_LOG_ERROR("Message Type: Error");
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions sdk/samples/iot/paho_iot_hub_pnp_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ static void handle_device_twin_message(
case AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES:
IOT_SAMPLE_LOG("Message Type: Reported Properties");
break;

// An error response.
case AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_ERROR:
IOT_SAMPLE_LOG_ERROR("Message Type: Error");
break;
}
}

Expand Down
4 changes: 4 additions & 0 deletions sdk/samples/iot/paho_iot_hub_twin_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ static void handle_device_twin_message(
(void)receive_device_twin_message();
}
break;

case AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_ERROR:
IOT_SAMPLE_LOG_ERROR("Message Type: Error");
break;
}
}

Expand Down
10 changes: 8 additions & 2 deletions sdk/src/azure/iot/az_iot_hub_client_twin.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,20 @@ AZ_NODISCARD az_result az_iot_hub_client_twin_parse_received_topic(
_az_RETURN_IF_FAILED(az_iot_message_properties_find(
&props, az_iot_hub_client_request_id_span, &out_response->request_id));

if (out_response->status == AZ_IOT_STATUS_NO_CONTENT)
if (out_response->status >= AZ_IOT_STATUS_BAD_REQUEST) // 400+
{
// Is an error response
out_response->response_type = AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_ERROR;
out_response->version = AZ_SPAN_EMPTY;
}
else if (out_response->status == AZ_IOT_STATUS_NO_CONTENT) // 204
{
// Is a reported prop response
out_response->response_type = AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_REPORTED_PROPERTIES;
_az_RETURN_IF_FAILED(az_iot_message_properties_find(
&props, az_iot_hub_twin_version_prop, &out_response->version));
}
else
else // 200 or 202
{
// Is a twin GET response
out_response->response_type = AZ_IOT_HUB_CLIENT_TWIN_RESPONSE_TYPE_GET;
Expand Down