Skip to content

Commit 7910fc5

Browse files
tokangasnordicjm
authored andcommitted
net: lib: nrf_cloud_rest: Improve error logging
Improved logging when REST request fails. Signed-off-by: Tommi Kangas <[email protected]>
1 parent 51424e2 commit 7910fc5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

subsys/net/lib/nrf_cloud/src/nrf_cloud_rest.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ static void sync_rest_client_data(struct nrf_cloud_rest_context *const rest_ctx,
219219
}
220220
}
221221

222+
static void rest_error_response_log(struct nrf_cloud_rest_context *const rest_ctx)
223+
{
224+
LOG_ERR("REST request was rejected. Response status: %d", rest_ctx->status);
225+
if (rest_ctx->response && rest_ctx->response_len > 0) {
226+
LOG_ERR("Response body: %.*s",
227+
MIN(rest_ctx->response_len, 256), rest_ctx->response);
228+
}
229+
}
230+
222231
static int do_rest_client_request(struct nrf_cloud_rest_context *const rest_ctx,
223232
struct rest_client_req_context *const req,
224233
struct rest_client_resp_context *const resp,
@@ -243,16 +252,17 @@ static int do_rest_client_request(struct nrf_cloud_rest_context *const rest_ctx,
243252
}
244253

245254
if (ret) {
246-
LOG_DBG("REST client request failed with error code %d", ret);
255+
LOG_ERR("REST client request failed with error code %d", ret);
247256
return ret;
248257
} else if (rest_ctx->status == NRF_CLOUD_HTTP_STATUS_NONE) {
249-
LOG_DBG("REST request endpoint closed connection without reply.");
258+
LOG_ERR("REST request endpoint closed connection without reply.");
250259
return -ESHUTDOWN;
251260
} else if (check_status_good && (rest_ctx->status != NRF_CLOUD_HTTP_STATUS_OK) &&
252261
(rest_ctx->status != NRF_CLOUD_HTTP_STATUS_ACCEPTED)) {
253-
LOG_DBG("REST request was rejected. Response status: %d", rest_ctx->status);
262+
rest_error_response_log(rest_ctx);
254263
return -EBADMSG;
255264
} else if (expect_body && (!rest_ctx->response || !rest_ctx->response_len)) {
265+
LOG_ERR("REST response without body received.");
256266
return -ENODATA;
257267
}
258268

@@ -476,6 +486,7 @@ int nrf_cloud_rest_fota_job_get(struct nrf_cloud_rest_context *const rest_ctx,
476486

477487
if (rest_ctx->status != NRF_CLOUD_HTTP_STATUS_OK &&
478488
rest_ctx->status != NRF_CLOUD_HTTP_STATUS_NOT_FOUND) {
489+
rest_error_response_log(rest_ctx);
479490
ret = -EBADMSG;
480491
goto clean_up;
481492
}
@@ -827,6 +838,7 @@ int nrf_cloud_rest_agnss_data_get(struct nrf_cloud_rest_context *const rest_ctx,
827838
}
828839

829840
if (rest_ctx->status != NRF_CLOUD_HTTP_STATUS_PARTIAL) {
841+
rest_error_response_log(rest_ctx);
830842
ret = -EBADMSG;
831843
goto clean_up;
832844
}
@@ -1312,6 +1324,7 @@ int nrf_cloud_rest_shadow_transform_request(struct nrf_cloud_rest_context *const
13121324
}
13131325

13141326
if (rest_ctx->status != NRF_CLOUD_HTTP_STATUS_OK) {
1327+
rest_error_response_log(rest_ctx);
13151328
ret = -EBADMSG;
13161329
goto clean_up;
13171330
}

0 commit comments

Comments
 (0)