@@ -79,7 +79,7 @@ def create(cls, app: FastAPI, session_cookies: Dict):
79
79
)
80
80
81
81
def _url (self , path : str ) -> str :
82
- return f"/{ self .vtag } /{ path .ltrip ('/' )} "
82
+ return f"/{ self .vtag } /{ path .lstrip ('/' )} "
83
83
84
84
@classmethod
85
85
def _process (cls , resp : Response ) -> Optional [Dict ]:
@@ -107,14 +107,26 @@ def _process(cls, resp: Response) -> Optional[Dict]:
107
107
return data
108
108
109
109
# OPERATIONS
110
- # TODO: automate conversion
110
+ # TODO: refactor and code below
111
+ # TODO: policy to retry if NetworkError/timeout?
112
+ # TODO: add ping to healthcheck
111
113
112
114
async def get (self , path : str ) -> Optional [Dict ]:
113
115
url = self ._url (path )
114
- resp = await self .client .get (url , cookies = self .session_cookies )
116
+ try :
117
+ resp = await self .client .get (url , cookies = self .session_cookies )
118
+ except Exception :
119
+ logger .exception ("Failed to get %s" , url )
120
+ raise HTTPException (status .HTTP_503_SERVICE_UNAVAILABLE )
121
+
115
122
return self ._process (resp )
116
123
117
124
async def put (self , path : str , body : Dict ) -> Optional [Dict ]:
118
125
url = self ._url (path )
119
- resp = await self .client .put (url , json = body , cookies = self .session_cookies )
126
+ try :
127
+ resp = await self .client .put (url , json = body , cookies = self .session_cookies )
128
+ except Exception :
129
+ logger .exception ("Failed to put %s" , url )
130
+ raise HTTPException (status .HTTP_503_SERVICE_UNAVAILABLE )
131
+
120
132
return self ._process (resp )
0 commit comments