[coap] Bugfix: CoAP not sending 4.04 when URI handler is not found (#8297)

Update CoAP base handler to correctly detect when a handler is not
found and send a 4.04 response.

Prior to this change, the error code would be overridden in the case
where a URI handler was not found to kErrorNone. This meant that when
the exit code was reached, no 4.04 message was generated. This fixes
the logical flow to ensure the error message is sent on the link.
This commit is contained in:
Tom Rebbert
2022-10-20 20:24:05 -06:00
committed by GitHub
parent d8509e6254
commit 488ee63b4c
+6 -3
View File
@@ -1302,7 +1302,7 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
{
char uriPath[Message::kMaxReceivedUriPath + 1];
Message *cachedResponse = nullptr;
Error error = kErrorNotFound;
Error error = kErrorNone;
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
Option::Iterator iterator;
char * curUriPath = uriPath;
@@ -1320,10 +1320,10 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
case kErrorNone:
cachedResponse->Finish();
error = Send(*cachedResponse, aMessageInfo);
OT_FALL_THROUGH;
ExitNow();
case kErrorNoBufs:
error = kErrorNoBufs;
ExitNow();
case kErrorNotFound:
@@ -1453,8 +1453,11 @@ void CoapBase::ProcessReceivedRequest(Message &aMessage, const Ip6::MessageInfo
{
mDefaultHandler(mDefaultHandlerContext, &aMessage, &aMessageInfo);
error = kErrorNone;
ExitNow();
}
error = kErrorNotFound;
exit:
if (error != kErrorNone)