Skip to content

Commit

Permalink
Added easier to detect error message when search returns 0 results. T…
Browse files Browse the repository at this point in the history
…his currently parses html result from the mailarchive system, but when we get proper API to mailarchive system it should be changed to do that instead. Fixes #2126. Commit ready for merge.

 - Legacy-Id: 15706
  • Loading branch information
kivinen committed Nov 3, 2018
1 parent 56acd00 commit f9eeee0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ietf/doc/views_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,10 @@ def search_mail_archive(request, name, request_id):
try:
res["messages"] = mailarch.retrieve_messages(res["query_data_url"])[:MAX_RESULTS]
except Exception as e:
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
if unicode(e) == "NONE":
res["error"] = "No results found"
else:
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
# raise # useful when debugging

return JsonResponse(res)
Expand Down
4 changes: 4 additions & 0 deletions ietf/review/mailarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import datetime, tarfile, mailbox, tempfile, hashlib, base64, email.utils
import urllib
import urllib2, contextlib
import re

from django.conf import settings

Expand Down Expand Up @@ -92,6 +93,9 @@ def retrieve_messages(query_data_url):
with contextlib.closing(urllib2.urlopen(query_data_url, timeout=15)) as fileobj:
content_type = fileobj.info()["Content-type"]
if not content_type.startswith("application/x-tar"):
if content_type.startswith("text/html"):
if not re.search("no-results", fileobj.read(20000)) is None:
raise Exception("NONE")
raise Exception("Export failed - this usually means no matches were found")

with tarfile.open(fileobj=fileobj, mode='r|*') as tar:
Expand Down

0 comments on commit f9eeee0

Please sign in to comment.