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

Commit

Permalink
WIP - respond to Rob's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M Furley committed Mar 18, 2014
1 parent 23b69f1 commit 6fcf164
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions backdrop/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ def retrieve(self, name):
data_set_url = ('{url}/data-sets/{data_set_name}'.format(
url=self._stagecraft_url,
data_set_name=name))
json_response = _get_json_url(
data_set_url, self._stagecraft_token, swallow_404=True)
if json_response is not None:
return _make_bucket_config(_decode_json(json_response))

return None
try:
json_response = _get_json_url(data_set_url, self._stagecraft_token)
except requests.HTTPError as e:
if e.response.status_code == 404:
return None
else:
raise

return _make_bucket_config(_decode_json(json_response))

def get_bucket_for_query(self, data_group, data_type):
empty_vars = []
Expand Down Expand Up @@ -110,7 +114,7 @@ def _decode_json(string):
return json.loads(string) if string is not None else None


def _get_json_url(url, token, swallow_404=False):
def _get_json_url(url, token):
auth_header = (
'Authorization',
'Bearer {}'.format(token))
Expand All @@ -122,11 +126,6 @@ def _get_json_url(url, token, swallow_404=False):
except requests.HTTPError as e:
logger.exception(e)
logger.error('Stagecraft said: {}'.format(response.content))

if swallow_404 and e.response.status_code == 404:
logger.error('Got HTTP 404 for: {}'.format(url))
return None

raise
return response.content

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from backdrop.core.bucket import BucketConfig
from backdrop.core.repository import (BucketConfigRepository,
UserConfigRepository,
_get_json_url, StagecraftHttp404)
_get_json_url)
from hamcrest import assert_that, equal_to, is_, has_entries, match_equality
from mock import Mock, patch
from nose.tools import assert_raises
Expand Down

0 comments on commit 6fcf164

Please sign in to comment.