Raise a specific exception in utils.http.request for "wrong content type"
This commit is contained in:
parent
9193a51c55
commit
197ae2e053
1 changed files with 4 additions and 1 deletions
|
@ -16,6 +16,8 @@ class HTTPTimeoutException(HTTPException):
|
||||||
pass
|
pass
|
||||||
class HTTPParsingException(HTTPException):
|
class HTTPParsingException(HTTPException):
|
||||||
pass
|
pass
|
||||||
|
class HTTPWrongContentTypeException(HTTPException):
|
||||||
|
pass
|
||||||
|
|
||||||
def throw_timeout():
|
def throw_timeout():
|
||||||
raise HTTPTimeoutException()
|
raise HTTPTimeoutException()
|
||||||
|
@ -67,7 +69,8 @@ def request(url: str, method: str="GET", get_params: dict={},
|
||||||
soup = bs4.BeautifulSoup(response_content, parser)
|
soup = bs4.BeautifulSoup(response_content, parser)
|
||||||
return Response(response.status_code, soup, response_headers)
|
return Response(response.status_code, soup, response_headers)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Tried to soup non-html/non-xml data")
|
raise HTTPWrongContentTypeException(
|
||||||
|
"Tried to soup non-html/non-xml data")
|
||||||
|
|
||||||
|
|
||||||
data = response_content.decode(response.encoding or fallback_encoding)
|
data = response_content.decode(response.encoding or fallback_encoding)
|
||||||
|
|
Loading…
Reference in a new issue