Skip to content

Commit f9eeee0

Browse files
committed
Added easier to detect error message when search returns 0 results. This 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 ietf-tools#2126. Commit ready for merge.
- Legacy-Id: 15706
1 parent 56acd00 commit f9eeee0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

ietf/doc/views_review.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,10 @@ def search_mail_archive(request, name, request_id):
687687
try:
688688
res["messages"] = mailarch.retrieve_messages(res["query_data_url"])[:MAX_RESULTS]
689689
except Exception as e:
690-
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
690+
if unicode(e) == "NONE":
691+
res["error"] = "No results found"
692+
else:
693+
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
691694
# raise # useful when debugging
692695

693696
return JsonResponse(res)

ietf/review/mailarch.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import datetime, tarfile, mailbox, tempfile, hashlib, base64, email.utils
55
import urllib
66
import urllib2, contextlib
7+
import re
78

89
from django.conf import settings
910

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

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

0 commit comments

Comments
 (0)