Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename trace_id variable to correlation_id #408

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def request( # type: ignore[no-untyped-def]
**kwargs,
)

trace_id = response.headers.get("X-Correlation-Id")
correlation_id = response.headers.get("X-Correlation-Id")
payload = {}
try:
if len(response.content) > 0:
Expand All @@ -225,7 +225,7 @@ def request( # type: ignore[no-untyped-def]
code=response.status_code,
message=response.reason,
details={"content": response.content},
trace_id=trace_id,
correlation_id=correlation_id,
) from exc

if not response.ok:
Expand All @@ -234,7 +234,7 @@ def request( # type: ignore[no-untyped-def]
code=response.status_code,
message=response.reason,
details={"content": response.content},
trace_id=trace_id,
correlation_id=correlation_id,
)

error: dict = payload["error"]
Expand All @@ -248,7 +248,7 @@ def request( # type: ignore[no-untyped-def]
code=error["code"],
message=error["message"],
details=error["details"],
trace_id=trace_id,
correlation_id=correlation_id,
)

return payload
8 changes: 4 additions & 4 deletions hcloud/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def __init__(
message: str,
details: Any,
*,
trace_id: str | None = None,
correlation_id: str | None = None,
):
extras = [str(code)]
if trace_id is not None:
extras.append(trace_id)
if correlation_id is not None:
extras.append(correlation_id)

error = f"{message} ({', '.join(extras)})"

super().__init__(error)
self.code = code
self.message = message
self.details = details
self.trace_id = trace_id
self.correlation_id = correlation_id
4 changes: 2 additions & 2 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_request_fails(self, client, fail_response):
assert error.message == "invalid input in field 'broken_field': is too long"
assert error.details["fields"][0]["name"] == "broken_field"

def test_request_fails_trace_id(self, client, response):
def test_request_fails_correlation_id(self, client, response):
response.headers["X-Correlation-Id"] = "67ed842dc8bc8673"
response.status_code = 409
response._content = json.dumps(
Expand All @@ -124,7 +124,7 @@ def test_request_fails_trace_id(self, client, response):
assert error.code == "conflict"
assert error.message == "some conflict"
assert error.details is None
assert error.trace_id == "67ed842dc8bc8673"
assert error.correlation_id == "67ed842dc8bc8673"
assert str(error) == "some conflict (conflict, 67ed842dc8bc8673)"

def test_request_500(self, client, fail_response):
Expand Down