added RedirectSaveError - for failed saves if the URL is a permanent redirect.

This commit is contained in:
Akash Mahanty
2021-04-02 00:35:26 +05:30
parent db8f902cff
commit 8171c8e394
2 changed files with 15 additions and 1 deletions

View File

@@ -13,6 +13,13 @@ class WaybackError(Exception):
"""
class RedirectSaveError(WaybackError):
"""
Raised when the original URL is redirected and the
redirect URL is archived but not the original URL.
"""
class URLError(Exception):
"""
Raised when malformed URLs are passed as arguments.

View File

@@ -3,7 +3,7 @@ import time
import requests
from datetime import datetime
from .exceptions import WaybackError, URLError
from .exceptions import WaybackError, URLError, RedirectSaveError
from .__version__ import __version__
from urllib3.util.retry import Retry
@@ -414,6 +414,13 @@ def _archive_url_parser(header, url, latest_version=__version__, instance=None):
"Wayback Machine is malfunctioning or it refused to archive your URL."
"\nHeader:\n{header}".format(url=url, header=header)
)
if "save redirected" == header.strip():
raise RedirectSaveError(
"URL cannot be archived by wayback machine as it is a redirect.\nHeader:\n{header}".format(
header=header
)
)
else:
exc_message = (
"No archive URL found in the API response. "