Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #179 from alphagov/more_log_response_messages
Browse files Browse the repository at this point in the history
Give some information about buckets in error messages
  • Loading branch information
tombooth committed Dec 3, 2013
2 parents d7b688b + a55a4ea commit 4e65c8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions backdrop/read/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def health_check():
return jsonify(status='ok', message='database and buckets are fine')


def log_error_and_respond(message, status_code):
app.logger.error(message)
def log_error_and_respond(bucket, message, status_code):
app.logger.error('%s: %s' % (bucket, message))
return jsonify(status='error', message=message), status_code


Expand All @@ -108,7 +108,10 @@ def query(bucket_name):

def fetch(bucket_config):
if bucket_config is None or not bucket_config.queryable:
return log_error_and_respond('bucket not found', 404)
bname = "" if bucket_config is None else bucket_config.name + " "
return log_error_and_respond(
bname, 'bucket not found',
404)

if request.method == 'OPTIONS':
# OPTIONS requests are made by XHR as part of the CORS spec
Expand All @@ -121,14 +124,18 @@ def fetch(bucket_config):
bucket_config.raw_queries_allowed)

if not result.is_valid:
return log_error_and_respond(result.message, 400)
return log_error_and_respond(
bucket_config.name, result.message,
400)

bucket = Bucket(db, bucket_config)

try:
result_data = bucket.query(Query.parse(request.args)).data()
except InvalidOperationError:
return log_error_and_respond('invalid collect for that data', 400)
return log_error_and_respond(
bucket.bucket_name, 'invalid collect function',
400)

response = jsonify(data=result_data)

Expand Down
4 changes: 2 additions & 2 deletions features/read_api/collect.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: collect fields into grouped responses
then I should get back a status of "200"
and the "1st" result should have "value:sum" with json "27"
and the "1st" result should have "value:mean" with json "6.75"

Scenario: should be able to perform maths on sub groups
Given "evl_volumetrics.json" is in "foo" bucket
when I go to "/foo?period=month&group_by=channel&collect=volume:sum"
Expand All @@ -49,4 +49,4 @@ Feature: collect fields into grouped responses
Given "dinosaurs.json" is in "foo" bucket
when I go to "/foo?group_by=type&collect=name:sum"
then I should get back a status of "400"
and the error message should be "invalid collect for that data"

0 comments on commit 4e65c8c

Please sign in to comment.