3
3
import ssl
4
4
import requests
5
5
from requests .exceptions import *
6
- from . import cbLogs
6
+ from . import cbLogs , cbErrors
7
7
from .cbLogs import prettyText
8
8
9
9
@@ -31,7 +31,7 @@ def get(url, headers={}, params={}, silent=False, sslVerify=True):
31
31
resp = requests .get (url , headers = headers , params = params , verify = sslVerify )
32
32
except ConnectionError :
33
33
cbLogs .error ("Connection error. Check that" , url , "is up and accepting requests." )
34
- exit (- 1 )
34
+ cbErrors . handle (- 1 )
35
35
36
36
# check for errors
37
37
if resp .status_code == 200 :
@@ -41,7 +41,7 @@ def get(url, headers={}, params={}, silent=False, sslVerify=True):
41
41
resp = resp .text
42
42
elif not silent : # some requests are meant to fail
43
43
panicmessage (resp , "GET" , url , headers , params = params )
44
- exit (- 1 )
44
+ cbErrors . handle (- 1 )
45
45
46
46
# return successful response
47
47
return resp
@@ -60,14 +60,14 @@ def post(url, headers={}, data={}, silent=False, sslVerify=True, x509keyPair=Non
60
60
resp = requests .post (url , headers = headers , data = data , verify = sslVerify )
61
61
except ConnectionError :
62
62
cbLogs .error ("Connection error. Check that" , url , "is up and accepting requests." )
63
- exit (- 1 )
63
+ cbErrors . handle (- 1 )
64
64
else :
65
65
try :
66
66
# mTLS auth so load cert
67
67
resp = requests .post (url , headers = headers , data = data , verify = sslVerify , cert = (x509keyPair ["certfile" ], x509keyPair ["keyfile" ]))
68
68
except ConnectionError :
69
69
cbLogs .error ("Connection error. Check that" , url , "is up and accepting requests." )
70
- exit (- 1 )
70
+ cbErrors . handle (- 1 )
71
71
72
72
73
73
# check for errors
@@ -78,7 +78,7 @@ def post(url, headers={}, data={}, silent=False, sslVerify=True, x509keyPair=Non
78
78
resp = resp .text
79
79
elif not silent : # some requests are meant to fail
80
80
panicmessage (resp , "POST" , url , headers , data = data )
81
- exit (- 1 )
81
+ cbErrors . handle (- 1 )
82
82
83
83
# return successful response
84
84
return resp
@@ -96,7 +96,7 @@ def put(url, headers={}, data={}, silent=False, sslVerify=True):
96
96
resp = requests .put (url , headers = headers , data = data , verify = sslVerify )
97
97
except ConnectionError :
98
98
cbLogs .error ("Connection error. Check that" , url , "is up and accepting requests." )
99
- exit (- 1 )
99
+ cbErrors . handle (- 1 )
100
100
101
101
# check for errors
102
102
if resp .status_code == 200 :
@@ -106,7 +106,7 @@ def put(url, headers={}, data={}, silent=False, sslVerify=True):
106
106
resp = resp .text
107
107
elif not silent : # some requests are meant to fail
108
108
panicmessage (resp , "PUT" , url , headers , data = data )
109
- exit (- 1 )
109
+ cbErrors . handle (- 1 )
110
110
111
111
# return successful response
112
112
return resp
@@ -118,7 +118,7 @@ def delete(url, headers={}, params={}, silent=False, sslVerify=True):
118
118
resp = requests .delete (url , headers = headers , params = params , verify = sslVerify )
119
119
except ConnectionError :
120
120
cbLogs .error ("Connection error. Check that" , url , "is up and accepting requests." )
121
- exit (- 1 )
121
+ cbErrors . handle (- 1 )
122
122
123
123
# check for errors
124
124
if resp .status_code == 200 :
@@ -128,7 +128,7 @@ def delete(url, headers={}, params={}, silent=False, sslVerify=True):
128
128
resp = resp .text
129
129
elif not silent : # some requests are meant to fail
130
130
panicmessage (resp , "DELETE" , url , headers , params = params )
131
- exit (- 1 )
131
+ cbErrors . handle (- 1 )
132
132
133
133
# return successful response
134
134
return resp
0 commit comments