@@ -76,6 +76,8 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
7676 else :
7777 kwargs ['headers' ] = headers
7878
79+ return_on = kwargs .get ('return_on' , [])
80+
7981 if not url .startswith ('/' ):
8082 url = url [1 :]
8183
@@ -92,7 +94,12 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
9294 if self .session :
9395 async with self .session .request (method , url , ** kwargs ) as resp :
9496 js = await resp .json ()
95- if resp .status == 403 :
97+ if resp .status in return_on :
98+ if raw :
99+ return resp
100+ else :
101+ return js
102+ elif resp .status == 403 :
96103 raise Forbidden (resp , js )
97104 elif resp .status == 400 :
98105 raise BadRequest (resp , js )
@@ -113,7 +120,12 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
113120 async with aiohttp .ClientSession (loop = self .loop ) as sess :
114121 async with sess .request (method , url , ** kwargs ) as resp :
115122 js = await resp .json ()
116- if resp .status == 403 :
123+ if resp .status in return_on :
124+ if raw :
125+ return resp
126+ else :
127+ return js
128+ elif resp .status == 403 :
117129 raise Forbidden (resp , js )
118130 elif resp .status == 400 :
119131 raise BadRequest (resp , js )
@@ -158,7 +170,7 @@ async def lyrics(self, query: str) -> LyricResult:
158170 The Lyrics Result returned by the API.
159171 """
160172
161- js = await self ._request ('GET' , f'/api/lyrics/{ quote (query )} ' )
173+ js = await self ._request ('GET' , f'/api/lyrics/{ quote (query )} ' , return_on = [ 404 , 200 ] )
162174 return LyricResult (js )
163175
164176 async def nsfw_check (self , url : str ) -> NSFWCheckResult :
0 commit comments