mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 00:03:28 +01:00
cdx-api: when using cdx server api, return no captures 404 error in json format if output=json, plain text otherwise instead of as html #193
This commit is contained in:
parent
f47ae0bb7e
commit
1a37d789ed
@ -1,11 +1,13 @@
|
||||
from pywb.cdx.cdxserver import create_cdx_server
|
||||
|
||||
from pywb.utils.wbexception import NotFoundException
|
||||
from pywb.framework.basehandlers import BaseHandler
|
||||
from pywb.framework.wbrequestresponse import WbResponse
|
||||
|
||||
from pywb.webapp.query_handler import QueryHandler
|
||||
|
||||
from six.moves.urllib.parse import parse_qs
|
||||
import json
|
||||
import six
|
||||
|
||||
|
||||
@ -21,7 +23,18 @@ class CDXAPIHandler(BaseHandler):
|
||||
def __call__(self, wbrequest):
|
||||
params = self.extract_params_from_wsgi_env(wbrequest.env)
|
||||
|
||||
cdx_iter = self.index_handler.load_cdx(wbrequest, params)
|
||||
try:
|
||||
cdx_iter = self.index_handler.load_cdx(wbrequest, params)
|
||||
except NotFoundException:
|
||||
msg = 'No Captures found for: ' + params.get('url')
|
||||
if params.get('output') == 'json':
|
||||
msg = json.dumps(dict(error=msg))
|
||||
content_type='application/json'
|
||||
else:
|
||||
content_type='text/plain'
|
||||
|
||||
return WbResponse.text_response(msg, content_type=content_type,
|
||||
status='404 Not Found')
|
||||
|
||||
return WbResponse.text_stream(cdx_iter,
|
||||
content_type='text/plain')
|
||||
|
Loading…
x
Reference in New Issue
Block a user