Skip to content

Commit e939ae8

Browse files
committed
improve error structure
1 parent 179dd15 commit e939ae8

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

AWSIoTPythonSDK/core/protocol/mqtt_core.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
from AWSIoTPythonSDK.core.protocol.internal.defaults import METRICS_PREFIX
2929
from AWSIoTPythonSDK.core.protocol.internal.defaults import ALPN_PROTCOLS
3030
from AWSIoTPythonSDK.core.protocol.internal.events import FixedEventMids
31-
from AWSIoTPythonSDK.core.protocol.paho.client import MQTT_ERR_SUCCESS
32-
from AWSIoTPythonSDK.core.protocol.paho.client import MQTT_ERR_SUBACK_ERROR
31+
from AWSIoTPythonSDK.core.protocol.paho.client import MQTT_ERR_SUCCESS, SUBACK_ERROR
3332
from AWSIoTPythonSDK.exception.AWSIoTExceptions import connectError
3433
from AWSIoTPythonSDK.exception.AWSIoTExceptions import connectTimeoutException
3534
from AWSIoTPythonSDK.exception.AWSIoTExceptions import disconnectError
@@ -42,7 +41,7 @@
4241
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeQueueDisabledException
4342
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeQueueFullException
4443
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeQueueDisabledException
45-
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeError
44+
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeError, subackError
4645
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeTimeoutException
4746
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeError
4847
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeTimeoutException
@@ -311,9 +310,9 @@ def subscribe(self, topic, qos, message_callback=None):
311310
self._internal_async_client.remove_event_callback(mid)
312311
self._logger.error("Subscribe timed out")
313312
raise subscribeTimeoutException()
314-
if suback.data and suback.data[0] == MQTT_ERR_SUBACK_ERROR:
315-
self._logger.error(f"Subscribe error: {suback.data}")
316-
raise subscribeError(suback.data)
313+
if suback.data and suback.data[0] == SUBACK_ERROR:
314+
self._logger.error(f"Suback error return code: {suback.data[0]}")
315+
raise subackError(suback=suback.data)
317316
ret = True
318317
return ret
319318

AWSIoTPythonSDK/core/protocol/paho/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@
9797
CONNACK_REFUSED_BAD_USERNAME_PASSWORD = 4
9898
CONNACK_REFUSED_NOT_AUTHORIZED = 5
9999

100+
# SUBACK codes
101+
SUBACK_ERROR = 0x80
102+
100103
# Connection state
101104
mqtt_cs_new = 0
102105
mqtt_cs_connected = 1
@@ -137,8 +140,6 @@
137140
MSG_QUEUEING_DROP_OLDEST = 0
138141
MSG_QUEUEING_DROP_NEWEST = 1
139142

140-
# Packet Error Codes
141-
MQTT_ERR_SUBACK_ERROR = 0x80
142143

143144
if sys.version_info[0] < 3:
144145
sockpair_data = "0"

AWSIoTPythonSDK/exception/AWSIoTExceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class subscribeError(operationError.operationError):
7979
def __init__(self, errorCode):
8080
self.message = "Subscribe Error: " + str(errorCode)
8181

82+
class subackError(operationError.operationError):
83+
def __init__(self, suback=None):
84+
self.message = "Received Error suback. Subscription failed."
85+
self.suback = suback
86+
8287

8388
class subscribeQueueFullException(operationError.operationError):
8489
def __init__(self):

0 commit comments

Comments
 (0)