11from vrcpy ._hardtyping import *
22from vrcpy .request import *
3- from vrcpy .errors import *
3+ from vrcpy .errors import AlreadyLoggedInError
44from vrcpy import objects
55from vrcpy import aobjects
66
@@ -29,7 +29,6 @@ def fetch_me(self):
2929 '''
3030
3131 resp = self .api .call ("/auth/user" )
32- self ._raise_for_status (resp )
3332
3433 self .me = objects .CurrentUser (self , resp ["data" ])
3534 return self .me
@@ -82,7 +81,6 @@ def fetch_friends(self, offline=False, n=0, offset=0):
8281 last_count = 0
8382
8483 resp = self .api .call ("/auth/user/friends" , params = {"offset" : offset , "offline" : offline , "n" : newn })
85- self ._raise_for_status (resp )
8684
8785 for friend in resp ["data" ]:
8886 last_count += 1
@@ -104,8 +102,6 @@ def fetch_user_by_id(self, id):
104102 '''
105103
106104 resp = self .api .call ("/users/" + id )
107- self ._raise_for_status (resp )
108-
109105 return objects .User (self , resp ["data" ])
110106
111107 def fetch_user_by_name (self , name ):
@@ -117,8 +113,6 @@ def fetch_user_by_name(self, name):
117113 '''
118114
119115 resp = self .api .call ("/users/" + urllib .parse .urlencode (name )+ "/name" )
120- self ._raise_for_status (resp )
121-
122116 return objects .User (self , resp ["data" ])
123117
124118 # Avatar calls
@@ -132,8 +126,6 @@ def fetch_avatar(self, id):
132126 '''
133127
134128 resp = self .api .call ("/avatars/" + id )
135- self ._raise_for_status (resp )
136-
137129 return objects .Avatar (self , resp ["data" ])
138130
139131 def list_avatars (self , user : oString = None , featured : oBoolean = None , tag : oString = None ,\
@@ -160,7 +152,6 @@ def list_avatars(self, user: oString = None, featured: oBoolean = None, tag: oSt
160152 if platform : p ["platform" ] = platform
161153
162154 resp = self .api .call ("/avatars" , params = p )
163- self ._raise_for_status (resp )
164155
165156 avatars = []
166157 for avatar in resp ["data" ]:
@@ -179,8 +170,6 @@ def fetch_world(self, id):
179170 '''
180171
181172 resp = self .api .call ("/worlds/" + id )
182- self ._raise_for_status (resp )
183-
184173 return objects .World (self , resp ["data" ])
185174
186175 def logout (self ):
@@ -189,7 +178,6 @@ def logout(self):
189178 '''
190179
191180 resp = self .api .call ("/logout" , "PUT" )
192- self ._raise_for_status (resp )
193181
194182 self .api .new_session ()
195183 self .loggedIn = False
@@ -205,43 +193,11 @@ def login(self, username, password):
205193 auth = str (base64 .b64encode (auth .encode ()))[2 :- 1 ]
206194
207195 resp = self .api .call ("/auth/user" , headers = {"Authorization" : "Basic " + auth }, no_auth = True )
208- self ._raise_for_status (resp )
209196
210197 self .api .set_auth (auth )
211198 self .me = objects .CurrentUser (self , resp ["data" ])
212199 self .loggedIn = True
213200
214- def _raise_for_status (self , resp ):
215- def handle_400 ():
216- if resp ["data" ]["error" ]["message" ] == "These users are not friends" :
217- raise NotFriendsError ("These users are not friends" )
218- elif resp ["data" ]["error" ]["message" ] == "\" Users are already friends!\" " :
219- raise AlreadyFriendsError ("Users are already friends!" )
220-
221- def handle_401 ():
222- raise IncorrectLoginError (resp ["data" ]["error" ]["message" ])
223-
224- def handle_404 ():
225- msg = ""
226-
227- if type (resp ["data" ]) == bytes :
228- try : msg = json .loads (resp ["data" ].decode ())["error" ]
229- except : msg = str (resp ["data" ].decode ()).split ("\" error\" :\" " )[1 ].split ("\" ,\" " )[0 ]
230- else :
231- msg = resp ["data" ]["error" ]["message" ]
232-
233- raise NotFoundError (msg )
234-
235- switch = {
236- 400 : lambda : handle_400 (),
237- 401 : lambda : handle_401 (),
238- 404 : lambda : handle_404 ()
239- }
240-
241- if resp ["status" ] in switch : switch [resp ["status" ]]()
242- if resp ["status" ] != 200 : raise GeneralError ("Unhandled error occured: " + str (resp ["data" ]))
243- if "requiresTwoFactorAuth" in resp ["data" ]: raise TwoFactorAuthNotSupportedError ("2FA is not supported yet." )
244-
245201 def __init__ (self , verify = True ):
246202 self .api = Call (verify )
247203 self .loggedIn = False
@@ -257,9 +213,7 @@ async def fetch_me(self):
257213 '''
258214
259215 self .cacheFull = False
260-
261216 resp = await self .api .call ("/auth/user" )
262- self ._raise_for_status (resp )
263217
264218 self .me = aobjects .CurrentUser (self , resp ["data" ])
265219 return self .me
@@ -312,7 +266,6 @@ async def fetch_friends(self, offline=False, n=0, offset=0):
312266 last_count = 0
313267
314268 resp = await self .api .call ("/auth/user/friends" , params = {"offset" : offset , "offline" : offline , "n" : newn })
315- self ._raise_for_status (resp )
316269
317270 for friend in resp ["data" ]:
318271 last_count += 1
@@ -334,8 +287,6 @@ async def fetch_user_by_id(self, id):
334287 '''
335288
336289 resp = await self .api .call ("/users/" + id )
337- self ._raise_for_status (resp )
338-
339290 return aobjects .User (self , resp ["data" ])
340291
341292 async def fetch_user_by_name (self , name ):
@@ -347,8 +298,6 @@ async def fetch_user_by_name(self, name):
347298 '''
348299
349300 resp = await self .api .call ("/users/" + urllib .parse .urlencode (name )+ "/name" )
350- self ._raise_for_status (resp )
351-
352301 return aobjects .User (self , resp ["data" ])
353302
354303 # Avatar calls
@@ -362,8 +311,6 @@ async def fetch_avatar(self, id):
362311 '''
363312
364313 resp = await self .api .call ("/avatars/" + id )
365- self ._raise_for_status (resp )
366-
367314 return aobjects .Avatar (self , resp ["data" ])
368315
369316 async def list_avatars (self , user : oString = None , featured : oBoolean = None , tag : oString = None ,\
@@ -390,7 +337,6 @@ async def list_avatars(self, user: oString = None, featured: oBoolean = None, ta
390337 if platform : p ["platform" ] = platform
391338
392339 resp = await self .api .call ("/avatars" , params = p )
393- self ._raise_for_status (resp )
394340
395341 avatars = []
396342 for avatar in resp ["data" ]:
@@ -409,8 +355,6 @@ async def fetch_world(self, id):
409355 '''
410356
411357 resp = await self .api .call ("/worlds/" + id )
412- self ._raise_for_status (resp )
413-
414358 return aobjects .World (self , resp ["data" ])
415359
416360 async def login (self , username , password ):
@@ -424,7 +368,6 @@ async def login(self, username, password):
424368 auth = str (base64 .b64encode (auth .encode ()))[2 :- 1 ]
425369
426370 resp = await self .api .call ("/auth/user" , headers = {"Authorization" : "Basic " + auth }, no_auth = True )
427- self ._raise_for_status (resp )
428371
429372 self .api .openSession (auth )
430373 self .me = aobjects .CurrentUser (self , resp ["data" ])
@@ -436,7 +379,6 @@ async def logout(self):
436379 '''
437380
438381 resp = await self .api .call ("/logout" , "PUT" )
439- self ._raise_for_status (resp )
440382
441383 await self .api .closeSession ()
442384 await asyncio .sleep (0 )
0 commit comments