@@ -76,6 +76,8 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
76
76
else :
77
77
kwargs ['headers' ] = headers
78
78
79
+ return_on = kwargs .get ('return_on' , [])
80
+
79
81
if not url .startswith ('/' ):
80
82
url = url [1 :]
81
83
@@ -92,7 +94,12 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
92
94
if self .session :
93
95
async with self .session .request (method , url , ** kwargs ) as resp :
94
96
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 :
96
103
raise Forbidden (resp , js )
97
104
elif resp .status == 400 :
98
105
raise BadRequest (resp , js )
@@ -113,7 +120,12 @@ async def _request(self, method: str, url: str, **kwargs) -> typing.Union[dict,
113
120
async with aiohttp .ClientSession (loop = self .loop ) as sess :
114
121
async with sess .request (method , url , ** kwargs ) as resp :
115
122
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 :
117
129
raise Forbidden (resp , js )
118
130
elif resp .status == 400 :
119
131
raise BadRequest (resp , js )
@@ -158,7 +170,7 @@ async def lyrics(self, query: str) -> LyricResult:
158
170
The Lyrics Result returned by the API.
159
171
"""
160
172
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 ] )
162
174
return LyricResult (js )
163
175
164
176
async def nsfw_check (self , url : str ) -> NSFWCheckResult :
0 commit comments