Skip to content

Commit 190cdd1

Browse files
author
Andrew Higgins
authored
[improvement] Wrap HTTPError in ConjureHTTPError with SerializableError details (#22)
<!-- PR title should start with '[fix]', '[improvement]' or '[break]' if this PR would cause a patch, minor or major SemVer bump. Omit the prefix if this PR doesn't warrant a standalone release. --> ## Before this PR <!-- Describe the problem you encountered with the current state of the world (or link to an issue) and why it's important to fix now. --> `HTTPError` response content was parsed hoping to find `SerializableError` contents, though didn't extract all contents and relied on deprecated fields such as message. The original `HTTPError` and a message were then wrapped in a new `HTTPError` and reraised. ## After this PR <!-- Describe at a high-level why this approach is better. --> 1. The original `HTTPError` is wrapped in a way (`raise_from`) that is understandable to Python 3's improved traceback functionality. 2. The new `ConjureHTTPError` can be separately detected as such while maintaining a reference to its wrapped `cause`. 3. The new `ConjureHTTPError` contains attributes to access fields from `SerializableError`, as well as the `X-B3-TraceId` from response headers when possible. <!-- Reference any existing GitHub issues, e.g. 'fixes #000' or 'relevant to #000' --> See also #21.
1 parent 308d234 commit 190cdd1

File tree

8 files changed

+167
-95
lines changed

8 files changed

+167
-95
lines changed

.circleci/config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ jobs:
4747
command: pip install --user setuptools tox==2.9.1 tox-virtualenv-no-download
4848

4949
- restore_cache:
50-
key: tox-v2-py27-{{ checksum "tox.ini" }}
50+
key: tox-v2-py27-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
5151

5252
- run:
5353
name: Install tox things
5454
command: if [ ! -d ".tox" ]; then python -m tox -e py27 --notest; fi
5555

5656
- save_cache:
57-
key: tox-v2-py27-{{ checksum "tox.ini" }}
57+
key: tox-v2-py27-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
5858
paths:
5959
- .tox
6060

@@ -82,14 +82,14 @@ jobs:
8282
command: pip install --user setuptools tox==2.9.1 tox-virtualenv-no-download
8383

8484
- restore_cache:
85-
key: tox-v2-py3-{{ checksum "tox.ini" }}
85+
key: tox-v2-py3-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
8686

8787
- run:
8888
name: Install tox things
8989
command: if [ ! -d ".tox" ]; then python -m tox -e py3 --notest; fi
9090

9191
- save_cache:
92-
key: tox-v2-py3-{{ checksum "tox.ini" }}
92+
key: tox-v2-py3-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
9393
paths:
9494
- .tox
9595

@@ -114,14 +114,14 @@ jobs:
114114
command: pip install --user setuptools tox==2.9.1 tox-virtualenv-no-download
115115

116116
- restore_cache:
117-
key: tox-v2-mypy27-{{ checksum "tox.ini" }}
117+
key: tox-v2-mypy27-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
118118

119119
- run:
120120
name: Install tox things
121121
command: if [ ! -d ".tox" ]; then python -m tox -e mypy27 --notest; fi
122122

123123
- save_cache:
124-
key: tox-v2-mypy27-{{ checksum "tox.ini" }}
124+
key: tox-v2-mypy27-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
125125
paths:
126126
- .tox
127127

@@ -146,14 +146,14 @@ jobs:
146146
command: pip install --user setuptools tox==2.9.1 tox-virtualenv-no-download
147147

148148
- restore_cache:
149-
key: tox-v2-mypy3-{{ checksum "tox.ini" }}
149+
key: tox-v2-mypy3-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
150150

151151
- run:
152152
name: Install tox things
153153
command: if [ ! -d ".tox" ]; then python -m tox -e mypy3 --notest; fi
154154

155155
- save_cache:
156-
key: tox-v2-mypy3-{{ checksum "tox.ini" }}
156+
key: tox-v2-mypy3-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
157157
paths:
158158
- .tox
159159

@@ -178,14 +178,14 @@ jobs:
178178
command: pip install --user setuptools tox==2.9.1 tox-virtualenv-no-download
179179

180180
- restore_cache:
181-
key: tox-v2-lint-{{ checksum "tox.ini" }}
181+
key: tox-v2-lint-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
182182

183183
- run:
184184
name: Install tox things
185185
command: if [ ! -d ".tox" ]; then python -m tox -e lint --notest; fi
186186

187187
- save_cache:
188-
key: tox-v2-lint-{{ checksum "tox.ini" }}
188+
key: tox-v2-lint-{{ checksum "tox.ini" }}-({ checksum "Pipfile.lock" })
189189
paths:
190190
- .tox
191191

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ name = "pypi"
55

66
[packages]
77
"enum34" = "*"
8+
future = "*"
89
requests = "*"
910
typing = "*"
1011

Pipfile.lock

Lines changed: 64 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

conjure_python_client/_http/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# limitations under the License.
1414

1515
from .configuration import SslConfiguration, ServiceConfiguration
16-
from .requests_client import RequestsClient, Service
16+
from .requests_client import RequestsClient, Service, ConjureHTTPError
1717

1818
__all__ = [
19-
'SslConfiguration', 'ServiceConfiguration', 'RequestsClient', 'Service'
19+
'SslConfiguration', 'ServiceConfiguration', 'RequestsClient', 'Service',
20+
'ConjureHTTPError'
2021
]

0 commit comments

Comments
 (0)