From d6c7ac77c087460ff5c734504e684f155f59934d Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Mon, 8 Apr 2024 09:57:57 -0400 Subject: [PATCH] feat: pass error response content into raised exceptions --- .github/workflows/ci.yml | 4 ++-- CHANGELOG.rst | 4 ++++ braze/__init__.py | 2 +- braze/client.py | 11 ++++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6ed40f..a923d42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: python-version: ['3.8'] - toxenv: [quality, docs, 'py38'] + toxenv: [quality, 'py38'] env: RUNJSHINT: true steps: @@ -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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1e6cfd0..80d1772 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. diff --git a/braze/__init__.py b/braze/__init__.py index f196bdb..05a7e2e 100644 --- a/braze/__init__.py +++ b/braze/__init__.py @@ -2,4 +2,4 @@ Python client for interacting with Braze APIs. """ -__version__ = '0.2.2' +__version__ = '0.2.3' diff --git a/braze/client.py b/braze/client.py index 017e40d..63b640f 100644 --- a/braze/client.py +++ b/braze/client.py @@ -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 @@ -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