Sfoglia il codice sorgente

Return ClientResponse object from fetch only if the retrieval was successful

If an exception was raised and caught, the object is still present in the history.
tags/v0.2.2
JustAnotherArchivist 4 anni fa
parent
commit
c263ad0b03
1 ha cambiato i file con 4 aggiunte e 3 eliminazioni
  1. +4
    -3
      qwarc/__init__.py

+ 4
- 3
qwarc/__init__.py Vedi File

@@ -94,12 +94,13 @@ class Item:
if response and exc is None and writeToWarc:
self.warc.write_client_response(response)
history.append((response, exc))
retResponse = response if exc is None else None
if action in (ACTION_SUCCESS, ACTION_IGNORE):
return response, tuple(history)
return retResponse, tuple(history)
elif action == ACTION_FOLLOW_OR_SUCCESS:
redirectUrl = response.headers.get('Location') or response.headers.get('URI')
if not redirectUrl:
return response, tuple(history)
return retResponse, tuple(history)
url = url.join(yarl.URL(redirectUrl))
if response.status in (301, 302, 303) and method == 'POST':
method = 'GET'
@@ -107,7 +108,7 @@ class Item:
attempt = 0
elif action == ACTION_RETRIES_EXCEEDED:
self.logger.error(f'Request for {url} failed {attempt} times')
return response, tuple(history)
return retResponse, tuple(history)
elif action == ACTION_RETRY:
# Nothing to do, just go to the next cycle
pass


Caricamento…
Annulla
Salva