Skip to content

Commit 050523e

Browse files
authored
break out errors into explicit types (#44)
* added strict error checking for params in errors.py
1 parent e54e04e commit 050523e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Adafruit_IO/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
import json
2323

24+
# MQTT RC Error Types
25+
MQTT_ERRORS = [ 'Connection successful',
26+
'Incorrect protocol version',
27+
'Invalid Client ID',
28+
'Server unavailable ',
29+
'Bad username or password',
30+
'Not authorized' ]
31+
2432
class AdafruitIOError(Exception):
2533
"""Base class for all Adafruit IO request failures."""
2634
pass
@@ -49,3 +57,11 @@ def __init__(self):
4957
super(ThrottlingError, self).__init__("Exceeded the limit of Adafruit IO " \
5058
"requests in a short period of time. Please reduce the rate of requests " \
5159
"and try again later.")
60+
61+
class MQTTError(Exception):
62+
"""Handles connection attempt failed errors.
63+
"""
64+
def __init__(self, response):
65+
error = MQTT_ERRORS[response]
66+
super(MQTTError, self).__init__(error)
67+
pass

0 commit comments

Comments
 (0)