File tree Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Expand file tree Collapse file tree 3 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -64,12 +64,10 @@ def __init__(
64
64
65
65
event_hooks = {"response" : []}
66
66
if debug :
67
- event_hooks ["response" ].append (
68
- lambda response : self ._log_response (response )
69
- )
67
+ event_hooks ["response" ].append (self ._log_response )
70
68
71
69
if raise_on_error :
72
- event_hooks ["response" ].append (lambda response : response . raise_for_status () )
70
+ event_hooks ["response" ].append (self . _raise_on_status )
73
71
74
72
transport = None
75
73
base_url = host
@@ -91,7 +89,16 @@ def __init__(
91
89
transport = transport ,
92
90
)
93
91
92
+ async def _raise_on_status (self , response : httpx .Response ):
93
+ if response is None :
94
+ return
95
+
96
+ response .raise_for_status ()
97
+
94
98
async def _log_response (self , response : httpx .Response ):
99
+ if response is None :
100
+ return
101
+
95
102
req_prefix = "< "
96
103
res_prefix = "> "
97
104
request = response .request
Original file line number Diff line number Diff line change @@ -64,12 +64,10 @@ def __init__(
64
64
65
65
event_hooks = {"response" : []}
66
66
if debug :
67
- event_hooks ["response" ].append (
68
- lambda response : self ._log_response (response )
69
- )
67
+ event_hooks ["response" ].append (self ._log_response )
70
68
71
69
if raise_on_error :
72
- event_hooks ["response" ].append (lambda response : response . raise_for_status () )
70
+ event_hooks ["response" ].append (self . _raise_on_status )
73
71
74
72
transport = None
75
73
base_url = host
@@ -91,7 +89,16 @@ def __init__(
91
89
transport = transport ,
92
90
)
93
91
92
+ def _raise_on_status (self , response : httpx .Response ):
93
+ if response is None :
94
+ return
95
+
96
+ response .raise_for_status ()
97
+
94
98
def _log_response (self , response : httpx .Response ):
99
+ if response is None :
100
+ return
101
+
95
102
req_prefix = "< "
96
103
res_prefix = "> "
97
104
request = response .request
Original file line number Diff line number Diff line change 5
5
6
6
import anyio
7
7
8
- from cerbos .sdk .client import CerbosAsyncClient
8
+ from cerbos .sdk .client import AsyncCerbosClient
9
9
from cerbos .sdk .model import *
10
10
11
11
12
12
async def main ():
13
13
logging .basicConfig (level = logging .DEBUG )
14
14
logging .captureWarnings (True )
15
15
16
- async with CerbosAsyncClient (
16
+ async with AsyncCerbosClient (
17
17
"https://localhost:3592" ,
18
18
playground_instance = "XXY" ,
19
19
debug = True ,
20
20
tls_verify = False ,
21
+ raise_on_error = True ,
21
22
) as c :
22
23
p = Principal (
23
24
"john" ,
You can’t perform that action at this time.
0 commit comments