Skip to content

Commit

Permalink
feat: pass error response content into raised exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Apr 8, 2024
1 parent 08698ab commit d6c7ac7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
python-version: ['3.8']
toxenv: [quality, docs, 'py38']
toxenv: [quality, 'py38']
env:
RUNJSHINT: true
steps:
Expand All @@ -30,5 +30,5 @@ jobs:
if: matrix.python-version == '3.8' && matrix.toxenv=='py38'
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
fail_ci_if_error: false

4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[0.2.3]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feat: pass error response content into raised exceptions

[0.2.2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fix: be defensive about pulling both ``email`` and ``external_id`` from braze export.
Expand Down
2 changes: 1 addition & 1 deletion braze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Python client for interacting with Braze APIs.
"""

__version__ = '0.2.2'
__version__ = '0.2.3'
11 changes: 6 additions & 5 deletions braze/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,19 @@ def _make_request(self, data, endpoint, request_type):
except requests.exceptions.HTTPError as exc:
# https://www.braze.com/docs/api/errors/#fatal-errors
status_code = exc.response.status_code
response_content = exc.response.text

if status_code == 400:
raise BrazeBadRequestError from exc
raise BrazeBadRequestError(response_content) from exc

if status_code == 401:
raise BrazeUnauthorizedError from exc
raise BrazeUnauthorizedError(response_content) from exc

if status_code == 403:
raise BrazeForbiddenError from exc
raise BrazeForbiddenError(response_content) from exc

if status_code == 404:
raise BrazeNotFoundError from exc
raise BrazeNotFoundError(response_content) from exc

if status_code == 429:
headers = exc.response.headers
Expand All @@ -114,7 +115,7 @@ def _make_request(self, data, endpoint, request_type):
raise BrazeRateLimitError(reset_epoch_s) from exc

if str(status_code).startswith('5'):
raise BrazeInternalServerError from exc
raise BrazeInternalServerError(response_content) from exc

raise BrazeClientError from exc

Expand Down

0 comments on commit d6c7ac7

Please sign in to comment.