[twitter] distinguish between fatal & nonfatal errors (#2020)
only show a warning for nonfatal errors and do not raise a StopExtraction exception
This commit is contained in:
@@ -793,16 +793,21 @@ class TwitterAPI():
|
|||||||
data = response.json()
|
data = response.json()
|
||||||
if "errors" in data:
|
if "errors" in data:
|
||||||
try:
|
try:
|
||||||
msg = ", ".join(
|
errors, warnings = [], []
|
||||||
'"' + error["message"] + '"'
|
for error in data["errors"]:
|
||||||
for error in data["errors"]
|
if error.get("kind") == "NonFatal":
|
||||||
)
|
warnings.append(error["message"])
|
||||||
|
else:
|
||||||
|
errors.append(error["message"])
|
||||||
|
errors = ", ".join(errors)
|
||||||
except Exception:
|
except Exception:
|
||||||
msg = data["errors"]
|
errors = data["errors"]
|
||||||
if msg and response.status_code < 400:
|
if warnings:
|
||||||
raise exception.StopExtraction(msg)
|
self.extractor.log.warning(", ".join(warnings))
|
||||||
|
if errors and response.status_code < 400:
|
||||||
|
raise exception.StopExtraction(errors)
|
||||||
else:
|
else:
|
||||||
msg = ""
|
errors = ""
|
||||||
|
|
||||||
if response.status_code < 400:
|
if response.status_code < 400:
|
||||||
# success
|
# success
|
||||||
@@ -816,7 +821,7 @@ class TwitterAPI():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if response.status_code == 401 and \
|
if response.status_code == 401 and \
|
||||||
"have been blocked from viewing" in msg:
|
"have been blocked from viewing" in errors:
|
||||||
# account blocked
|
# account blocked
|
||||||
extr = self.extractor
|
extr = self.extractor
|
||||||
if self.headers["x-twitter-auth-type"] and \
|
if self.headers["x-twitter-auth-type"] and \
|
||||||
@@ -833,7 +838,7 @@ class TwitterAPI():
|
|||||||
|
|
||||||
# error
|
# error
|
||||||
raise exception.StopExtraction(
|
raise exception.StopExtraction(
|
||||||
"%s %s (%s)", response.status_code, response.reason, msg)
|
"%s %s (%s)", response.status_code, response.reason, errors)
|
||||||
|
|
||||||
def _pagination(self, endpoint, params=None):
|
def _pagination(self, endpoint, params=None):
|
||||||
if params is None:
|
if params is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user