[pixiv] raise NotFoundError instead of failing
This commit is contained in:
@@ -123,12 +123,16 @@ def main():
|
|||||||
except exception.AuthenticationError:
|
except exception.AuthenticationError:
|
||||||
print("Authentication failed. Please provide a valid "
|
print("Authentication failed. Please provide a valid "
|
||||||
"username/password pair.", file=sys.stderr)
|
"username/password pair.", file=sys.stderr)
|
||||||
|
except exception.NotFoundError as err:
|
||||||
|
res = str(err) or "resource (gallery/image/user)"
|
||||||
|
print("The ", res, " at '", url, "' does not exist",
|
||||||
|
sep="", file=sys.stderr)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nKeyboardInterrupt", file=sys.stderr)
|
print("\nKeyboardInterrupt", file=sys.stderr)
|
||||||
except BrokenPipeError:
|
except BrokenPipeError:
|
||||||
pass
|
pass
|
||||||
except IOError as e:
|
except IOError as err:
|
||||||
import errno
|
import errno
|
||||||
if e.errno != errno.EPIPE:
|
if err.errno != errno.EPIPE:
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -303,6 +303,9 @@ class PixivAPI():
|
|||||||
return user, "Bearer " + token
|
return user, "Bearer " + token
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse(response):
|
def _parse(response, empty=[None]):
|
||||||
"""Parse a Pixiv Public-API response"""
|
"""Parse a Pixiv Public-API response"""
|
||||||
return json.loads(response.text)
|
data = json.loads(response.text)
|
||||||
|
if data["status"] == "failure" or data["response"] == empty:
|
||||||
|
raise exception.NotFoundError()
|
||||||
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user