Skip to content

Commit 0449cff

Browse files
Merge pull request #52 from marblestation/propagate_http_errors
Because of how ADSWS works, HTTP errors weren't getting propagated correctly by just using `raise_for_status`. If we get to fix ADSWS, these changes could be reverted.
2 parents 918e095 + fd58814 commit 0449cff

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

solr/views.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import current_app, request
1+
from flask import current_app, request, abort, make_response, jsonify
22
from flask.ext.restful import Resource
33
from flask.ext.discoverer import advertise
44
try:
@@ -412,7 +412,7 @@ def _get_stream_data(self, params, streams, request, handler_class="default"):
412412
else:
413413
r = current_app.client.get(current_app.config['VAULT_ENDPOINT'] + '/' + value,
414414
headers=new_headers)
415-
r.raise_for_status()
415+
self._abort_for_status(r)
416416

417417
# json serialized dictionary with two keys, 'query' and 'bigquery'
418418
# their values are strings (for query urlencoded parameters)
@@ -456,7 +456,8 @@ def _harvest_library(self, library_id, headers):
456456
r = current_app.client.get(current_app.config['LIBRARY_ENDPOINT'] + '/' + library_id,
457457
params=params,
458458
headers=headers)
459-
r.raise_for_status()
459+
self._abort_for_status(r)
460+
460461
q = r.json()
461462
oldcount = len(out['documents'])
462463
out['documents'].update(q['documents'])
@@ -473,6 +474,15 @@ def _harvest_library(self, library_id, headers):
473474

474475
return out
475476

477+
def _abort_for_status(self, r):
478+
if not r.ok:
479+
try:
480+
message_dict = r.json()
481+
except ValueError:
482+
abort(make_response(jsonify(message=r.text), r.status_code))
483+
else:
484+
abort(make_response(jsonify(message_dict), r.status_code))
485+
476486

477487
class Tvrh(SolrInterface):
478488
"""Exposes the solr term-vector histogram endpoint"""

0 commit comments

Comments
 (0)