File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,12 @@ def __init__(
12
12
message : Optional [str ] = None ,
13
13
docs : Optional [str ] = None ,
14
14
permissions : Optional [List [str ]] = [],
15
+ status : Optional [int ] = None ,
15
16
) -> None :
16
17
self .message = message
17
18
self .docs = docs
18
19
self .permissions = permissions
20
+ self .status = status
19
21
20
22
super ().__init__ (message )
21
23
@@ -27,6 +29,9 @@ def __str__(self) -> str:
27
29
else :
28
30
msg = "An error occurred"
29
31
32
+ if status := self .status :
33
+ msg += f" (status code: { status } )"
34
+
30
35
if permissions := self .permissions :
31
36
msg += "\n \n Permissions Required:"
32
37
for perm in permissions :
Original file line number Diff line number Diff line change 21
21
__OCTOKIT_PATH__ = os .path .dirname (os .path .realpath (__file__ ))
22
22
23
23
__OCTOKIT_ERRORS__ = {
24
- 401 : GHASToolkitAuthenticationError ("Authentication / Permission Issue" ),
25
- 403 : GHASToolkitAuthenticationError ("Authentication / Permission Issue" ),
26
- 404 : GHASToolkitError ("Not Found" ),
27
- 429 : GHASToolkitError ("Rate limit hit" ),
28
- 500 : GHASToolkitError ("GitHub Server Error" ),
24
+ 401 : GHASToolkitAuthenticationError (
25
+ "Authentication / Permission Issue" , status = 401
26
+ ),
27
+ 403 : GHASToolkitAuthenticationError (
28
+ "Authentication / Permission Issue" , status = 403
29
+ ),
30
+ 404 : GHASToolkitError ("Not Found" , status = 404 ),
31
+ 429 : GHASToolkitError ("Rate limit hit" , status = 429 ),
32
+ 500 : GHASToolkitError ("GitHub Server Error" , status = 500 ),
29
33
}
30
34
31
35
@@ -228,6 +232,9 @@ def get(
228
232
if display_errors :
229
233
logger .error (f"Error code from server :: { response .status_code } " )
230
234
235
+ if error_handler :
236
+ return error_handler (response .status_code , response_json )
237
+
231
238
known_error = __OCTOKIT_ERRORS__ .get (response .status_code )
232
239
if known_error :
233
240
raise known_error
Original file line number Diff line number Diff line change 1
1
"""Test RestRequest class."""
2
+
2
3
import unittest
4
+ from ghastoolkit .errors import GHASToolkitError
3
5
import responses
4
6
5
7
from ghastoolkit .octokit .octokit import RestRequest
@@ -35,10 +37,10 @@ def test_errors(self):
35
37
status = 404 ,
36
38
)
37
39
38
- with self .assertRaises (Exception ):
40
+ with self .assertRaises (GHASToolkitError ):
39
41
self .rest .get ("/repos/{owner}/{repo}/secret-scanning/alerts" )
40
42
41
- with self .assertRaises (Exception ):
43
+ with self .assertRaises (GHASToolkitError ):
42
44
self .rest .get ("/repos/{owner}/{repo}/secret-scanning/alerts/1" )
43
45
44
46
@responses .activate
You can’t perform that action at this time.
0 commit comments