Skip to content

Commit a2e0654

Browse files
committed
fix: check response code of CoAP responses
1 parent 0bd0b6b commit a2e0654

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/src/binding_coap/coap_client.dart

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class CoapClient extends ProtocolClient {
193193
}
194194

195195
coapClient.close();
196+
response.checkResponseCode();
196197
return response.content;
197198
}
198199

lib/src/binding_coap/coap_extensions.dart

+12
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ extension ResponseExtension on CoapResponse {
153153
return Content(_contentType, _payloadStream);
154154
}
155155

156+
/// Checks the [code] of this [CoapResponse] and throws an [Exception] if it
157+
/// should indicate an error.
158+
void checkResponseCode() {
159+
if (code.isServerError) {
160+
throw CoapServerErrorException(this);
161+
}
162+
163+
if (code.isErrorResponse) {
164+
throw CoapClientErrorException(this);
165+
}
166+
}
167+
156168
/// Validates the payload and returns a serialized ACE creation hint if
157169
/// successful.
158170
AuthServerRequestCreationHint? get creationHint {

0 commit comments

Comments
 (0)