Skip to content

Commit a72be82

Browse files
juhaylinennordicjm
authored andcommitted
net: nrf_provisioning: Improve error handling
Distinguish error responses for 401 and 403 status codes Previously, both 401 (Unauthorized) and 403 (Forbidden) status codes returned the same error. Signed-off-by: Juha Ylinen <[email protected]>
1 parent 325c1a7 commit a72be82

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

subsys/net/lib/nrf_provisioning/src/nrf_provisioning_coap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,16 @@ static int response_code_to_error(int code)
436436
{
437437
switch (code) {
438438
case COAP_RESPONSE_CODE_UNAUTHORIZED:
439-
LOG_ERR("Device didn't send auth credentials");
439+
LOG_ERR("Device not authorized");
440440
return -EACCES;
441441
case COAP_RESPONSE_CODE_FORBIDDEN:
442442
LOG_ERR("Device provided wrong auth credentials");
443-
return -EACCES;
443+
return -EPERM;
444444
case COAP_RESPONSE_CODE_BAD_REQUEST:
445445
LOG_ERR("Bad request");
446446
return -EINVAL;
447447
case COAP_RESPONSE_CODE_NOT_ACCEPTABLE:
448-
LOG_ERR("Not acceptable");
448+
LOG_ERR("Invalid Accept Headers");
449449
return -EINVAL;
450450
case COAP_RESPONSE_CODE_NOT_FOUND:
451451
LOG_ERR("Resource not found");

subsys/net/lib/nrf_provisioning/src/nrf_provisioning_http.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,11 @@ static int status_code_to_error(int status_code)
309309
LOG_ERR("Bad request");
310310
return -EINVAL;
311311
case NRF_PROVISIONING_HTTP_STATUS_UNAUTH:
312-
LOG_ERR("Device didn't send auth credentials");
312+
LOG_ERR("Device not authorized");
313313
return -EACCES;
314314
case NRF_PROVISIONING_HTTP_STATUS_FORBIDDEN:
315315
LOG_ERR("Device provided wrong auth credentials");
316-
return -EACCES;
316+
return -EPERM;
317317
case NRF_PROVISIONING_HTTP_STATUS_UNS_MEDIA_TYPE:
318318
LOG_ERR("Unsupported content format");
319319
return -ENOMSG;

tests/subsys/net/lib/nrf_provisioning/src/coap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void test_coap_auth_failed(void)
484484

485485
int ret = nrf_provisioning_coap_req(&coap_ctx);
486486

487-
TEST_ASSERT_EQUAL_INT(-EACCES, ret);
487+
TEST_ASSERT_EQUAL_INT(-EPERM, ret);
488488
}
489489

490490
/*

tests/subsys/net/lib/nrf_provisioning/src/scheduled.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int rest_client_request_not_found_cb(struct rest_client_req_context *req_
168168
struct rest_client_resp_context *resp_ctx,
169169
int cmock_num_calls)
170170
{
171-
resp_ctx->http_status_code = NRF_PROVISIONING_HTTP_STATUS_FORBIDDEN;
171+
resp_ctx->http_status_code = NRF_PROVISIONING_HTTP_STATUS_UNAUTH;
172172
return 0;
173173
}
174174

@@ -265,7 +265,7 @@ void test_provisioning_init_should_start_provisioning(void)
265265
wait_for_provisioning_event(NRF_PROVISIONING_EVENT_START);
266266

267267
/* Test different scenarios in rotation */
268-
int scenario = i % 6;
268+
int scenario = i % 7;
269269

270270
switch (scenario) {
271271
case 0: /* No commands from server */

0 commit comments

Comments
 (0)