Skip to content

Commit daad2a4

Browse files
committed
Cleanup ErrorHandler function
1 parent b879eb8 commit daad2a4

10 files changed

Lines changed: 43 additions & 43 deletions

examples/GE EGD exchanges example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727

2828
def ErrorHandler(err):
2929
# Generic Handler for exception errors
30-
if err.__class__ is error.KepError:
31-
print(err.msg)
32-
elif err.__class__ is error.KepHTTPError:
30+
if isinstance(err, error.KepHTTPError):
3331
print(err.code)
3432
print(err.msg)
3533
print(err.url)
3634
print(err.hdrs)
3735
print(err.payload)
38-
elif err.__class__ is error.KepURLError:
36+
elif isinstance(err, error.KepURLError):
3937
print(err.url)
4038
print(err.reason)
39+
elif isinstance(err, error.KepError):
40+
print(err.msg)
4141
else:
4242
print('Different Exception Received: {}'.format(err))
4343

examples/complex-example/Modbus2MQTT_MultiServer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@
2424

2525
import csv
2626
import json
27-
import kepconfig
27+
from kepconfig import error, connection
2828
from kepconfig.connectivity import channel, device
2929
import kepconfig.iot_gateway as IoT
3030

3131
def ErrorHandler(err):
3232
# Generic Handler for exception errors
33-
if err.__class__ is kepconfig.error.KepError:
34-
print(err.msg)
35-
elif err.__class__ is kepconfig.error.KepHTTPError:
33+
if isinstance(err, error.KepHTTPError):
3634
print(err.code)
3735
print(err.msg)
3836
print(err.url)
3937
print(err.hdrs)
4038
print(err.payload)
41-
elif err.__class__ is kepconfig.error.KepURLError:
39+
elif isinstance(err, error.KepURLError):
4240
print(err.url)
4341
print(err.reason)
42+
elif isinstance(err, error.KepError):
43+
print(err.msg)
4444
else:
4545
print('Different Exception Received: {}'.format(err))
4646

@@ -211,7 +211,7 @@ def make_tags(master_list, device, ttag, limit, titem):
211211

212212
print ("-- Channel and devices and agent creation attempt")
213213
for Kepware_IP in Kepware_IP_Array:
214-
server = kepconfig.connection.server(Kepware_IP, Kepware_Port, user, passw)
214+
server = connection.server(Kepware_IP, Kepware_Port, user, passw)
215215
try:
216216
print("{} - {}".format("Adding all devices", channel.add_channel(server,all_devices_JSON)))
217217
except Exception as err:

examples/datalogger example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@
5858

5959
def ErrorHandler(err):
6060
# Generic Handler for exception errors
61-
if err.__class__ is error.KepError:
62-
print(err.msg)
63-
elif err.__class__ is error.KepHTTPError:
61+
if isinstance(err, error.KepHTTPError):
6462
print(err.code)
6563
print(err.msg)
6664
print(err.url)
6765
print(err.hdrs)
6866
print(err.payload)
69-
elif err.__class__ is error.KepURLError:
67+
elif isinstance(err, error.KepURLError):
7068
print(err.url)
7169
print(err.reason)
70+
elif isinstance(err, error.KepError):
71+
print(err.msg)
7272
else:
7373
print('Different Exception Received: {}'.format(err))
74-
74+
7575
# This creates a server reference that is used to target all modifications of
7676
# the Kepware configuration
7777
server = connection.server(host = '127.0.0.1', port = 57412, user = 'Administrator', pw = '')

examples/iot gateway example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222

2323
def ErrorHandler(err):
2424
# Generic Handler for exception errors
25-
if err.__class__ is error.KepError:
26-
print(err.msg)
27-
elif err.__class__ is error.KepHTTPError:
25+
if isinstance(err, error.KepHTTPError):
2826
print(err.code)
2927
print(err.msg)
3028
print(err.url)
3129
print(err.hdrs)
3230
print(err.payload)
33-
elif err.__class__ is error.KepURLError:
31+
elif isinstance(err, error.KepURLError):
3432
print(err.url)
3533
print(err.reason)
34+
elif isinstance(err, error.KepError):
35+
print(err.msg)
3636
else:
3737
print('Different Exception Received: {}'.format(err))
3838

examples/kepware lls config example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
def ErrorHandler(err):
1414
# Generic Handler for exception errors
15-
if err.__class__ is error.KepError:
16-
print(err.msg)
17-
elif err.__class__ is error.KepHTTPError:
15+
if isinstance(err, error.KepHTTPError):
1816
print(err.code)
1917
print(err.msg)
2018
print(err.url)
2119
print(err.hdrs)
2220
print(err.payload)
23-
elif err.__class__ is error.KepURLError:
21+
elif isinstance(err, error.KepURLError):
2422
print(err.url)
2523
print(err.reason)
24+
elif isinstance(err, error.KepError):
25+
print(err.msg)
2626
else:
2727
print('Different Exception Received: {}'.format(err))
2828

examples/services and logs example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121

2222
def ErrorHandler(err):
2323
# Generic Handler for exception errors
24-
if err.__class__ is error.KepError:
25-
print(err.msg)
26-
elif err.__class__ is error.KepHTTPError:
24+
if isinstance(err, error.KepHTTPError):
2725
print(err.code)
2826
print(err.msg)
2927
print(err.url)
3028
print(err.hdrs)
3129
print(err.payload)
32-
elif err.__class__ is error.KepURLError:
30+
elif isinstance(err, error.KepURLError):
3331
print(err.url)
3432
print(err.reason)
33+
elif isinstance(err, error.KepError):
34+
print(err.msg)
3535
else:
3636
print('Different Exception Received: {}'.format(err))
3737

examples/simple connectivity example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
def ErrorHandler(err):
2020
# Generic Handler for exception errors
21-
if err.__class__ is error.KepError:
22-
print(err.msg)
23-
elif err.__class__ is error.KepHTTPError:
21+
if isinstance(err, error.KepHTTPError):
2422
print(err.code)
2523
print(err.msg)
2624
print(err.url)
2725
print(err.hdrs)
2826
print(err.payload)
29-
elif err.__class__ is error.KepURLError:
27+
elif isinstance(err, error.KepURLError):
3028
print(err.url)
3129
print(err.reason)
30+
elif isinstance(err, error.KepError):
31+
print(err.msg)
3232
else:
3333
print('Different Exception Received: {}'.format(err))
3434

examples/ua server config example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
}
3535
def ErrorHandler(err):
3636
# Generic Handler for exception errors
37-
if err.__class__ is error.KepError:
38-
print(err.msg)
39-
elif err.__class__ is error.KepHTTPError:
37+
if isinstance(err, error.KepHTTPError):
4038
print(err.code)
4139
print(err.msg)
4240
print(err.url)
4341
print(err.hdrs)
4442
print(err.payload)
45-
elif err.__class__ is error.KepURLError:
43+
elif isinstance(err, error.KepURLError):
4644
print(err.url)
4745
print(err.reason)
46+
elif isinstance(err, error.KepError):
47+
print(err.msg)
4848
else:
4949
print('Different Exception Received: {}'.format(err))
5050

examples/user management example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@
7171

7272
def ErrorHandler(err):
7373
# Generic Handler for exception errors
74-
if err.__class__ is error.KepError:
75-
print(err.msg)
76-
elif err.__class__ is error.KepHTTPError:
74+
if isinstance(err, error.KepHTTPError):
7775
print(err.code)
7876
print(err.msg)
7977
print(err.url)
8078
print(err.hdrs)
8179
print(err.payload)
82-
elif err.__class__ is error.KepURLError:
80+
elif isinstance(err, error.KepURLError):
8381
print(err.url)
8482
print(err.reason)
83+
elif isinstance(err, error.KepError):
84+
print(err.msg)
8585
else:
8686
print('Different Exception Received: {}'.format(err))
8787

tests/udd_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@
3030

3131
def ErrorHandler(err):
3232
# Generic Handler for exception errors
33-
if err.__class__ is error.KepError:
34-
print(err.msg)
35-
elif err.__class__ is error.KepHTTPError:
33+
if isinstance(err, error.KepHTTPError):
3634
print(err.code)
3735
print(err.msg)
3836
print(err.url)
3937
print(err.hdrs)
4038
print(err.payload)
41-
elif err.__class__ is error.KepURLError:
39+
elif isinstance(err, error.KepURLError):
4240
print(err.url)
4341
print(err.reason)
42+
elif isinstance(err, error.KepError):
43+
print(err.msg)
4444
else:
4545
print('Different Exception Received: {}'.format(err))
4646

0 commit comments

Comments
 (0)