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

Add ServerError exception #229

Merged
merged 2 commits into from
Dec 4, 2023
Merged

Conversation

jacobtomlinson
Copy link
Member

Closes #118.

When we get an httpx.HTTPStatusError that we can't recover from there is usually a lot of information about what went wrong in the body of the response. This PR reraises that exception as a kr8s.ServerError which exposes the response status directly.

>>> from kr8s.objects import Pod
>>> pod = Pod(invalid_pod_spec)
>>> pod.create()
ServerError: Pod "my-pod" is invalid: spec.containers[0].name: Required value

This is much more useful that the previous HTTPStatusError: Client error '422 Unprocessable Entity' for url 'https://127.0.0.1:37237/api/v1/namespaces/default/pods' exception.

The ServerError exception also has a .status attribute with the full server-side status object and a .response attribute with the httpx.Response object.

@jacobtomlinson jacobtomlinson merged commit 4e87c09 into kr8s-org:main Dec 4, 2023
7 checks passed
@jacobtomlinson jacobtomlinson deleted the servererror branch December 4, 2023 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise more useful API errors
1 participant