Skip to content

release: 0.1.3 #105

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

Merged
merged 5 commits into from
Sep 26, 2023
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.2"
".": "0.1.3"
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.1.3 (2023-09-25)

Full Changelog: [v0.1.2...v0.1.3](https://github.com/Finch-API/finch-api-python/compare/v0.1.2...v0.1.3)

### Features

* **ci:** add reviewers ([#106](https://github.com/Finch-API/finch-api-python/issues/106)) ([6cced26](https://github.com/Finch-API/finch-api-python/commit/6cced26464cfd952be880617e0b1fd8321d4ecff))
* **package:** export a root error type ([#108](https://github.com/Finch-API/finch-api-python/issues/108)) ([9ddf707](https://github.com/Finch-API/finch-api-python/commit/9ddf707ef7480471ee19e8fa426c47a3232ad736))


### Bug Fixes

* **client:** don't error by default for unexpected content types ([#104](https://github.com/Finch-API/finch-api-python/issues/104)) ([61dd6ba](https://github.com/Finch-API/finch-api-python/commit/61dd6ba7db2c872d6b234dad3a5abd8a3299cb86))


### Chores

* **internal:** move error classes from _base_exceptions to _exceptions (⚠️ breaking) ([#107](https://github.com/Finch-API/finch-api-python/issues/107)) ([6f6c4a1](https://github.com/Finch-API/finch-api-python/commit/6f6c4a14052fcfba58c8ef9c990f5a7817a59a24))

## 0.1.2 (2023-09-19)

Full Changelog: [v0.1.1...v0.1.2](https://github.com/Finch-API/finch-api-python/compare/v0.1.1...v0.1.2)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "finch-api"
version = "0.1.2"
version = "0.1.3"
description = "Client library for the Finch API"
readme = "README.md"
authors = ["Finch <[email protected]>"]
Expand Down
5 changes: 5 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
"hidden": true
}
],
"reviewers": [
"jordanbrauer",
"M-Shehu",
"johnny-finch"
],
"release-type": "python",
"extra-files": [
"src/finch/_version.py"
Expand Down
18 changes: 10 additions & 8 deletions src/finch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._version import __title__, __version__
from ._exceptions import (
APIError,
FinchError,
ConflictError,
NotFoundError,
APIStatusError,
Expand All @@ -38,19 +39,20 @@
"NoneType",
"Transport",
"ProxiesTypes",
"FinchError",
"APIError",
"APIConnectionError",
"APIResponseValidationError",
"APIStatusError",
"APITimeoutError",
"AuthenticationError",
"APIConnectionError",
"APIResponseValidationError",
"BadRequestError",
"ConflictError",
"InternalServerError",
"NotFoundError",
"AuthenticationError",
"PermissionDeniedError",
"RateLimitError",
"NotFoundError",
"ConflictError",
"UnprocessableEntityError",
"RateLimitError",
"InternalServerError",
"Timeout",
"RequestOptions",
"Client",
Expand All @@ -65,7 +67,7 @@
# Update the __module__ attribute for exported symbols so that
# error messages point to this module instead of the module
# it was originally defined in, e.g.
# finch._base_exceptions.NotFoundError -> finch.NotFoundError
# finch._exceptions.NotFoundError -> finch.NotFoundError
__locals = locals()
for __name in __all__:
if not __name.startswith("__"):
Expand Down
66 changes: 25 additions & 41 deletions src/finch/_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from httpx import URL, Limits
from pydantic import PrivateAttr

from . import _base_exceptions as exceptions
from . import _exceptions
from ._qs import Querystring
from ._types import (
NOT_GIVEN,
Expand Down Expand Up @@ -64,7 +64,7 @@
construct_type,
)
from ._streaming import Stream, AsyncStream
from ._base_exceptions import (
from ._exceptions import (
APIStatusError,
APITimeoutError,
APIConnectionError,
Expand Down Expand Up @@ -335,7 +335,6 @@ def __init__(

def _make_status_error_from_response(
self,
request: httpx.Request,
response: httpx.Response,
) -> APIStatusError:
err_text = response.text.strip()
Expand All @@ -347,33 +346,16 @@ def _make_status_error_from_response(
except Exception:
err_msg = err_text or f"Error code: {response.status_code}"

return self._make_status_error(err_msg, body=body, request=request, response=response)
return self._make_status_error(err_msg, body=body, response=response)

def _make_status_error(
self,
err_msg: str,
*,
body: object,
request: httpx.Request,
response: httpx.Response,
) -> APIStatusError:
if response.status_code == 400:
return exceptions.BadRequestError(err_msg, request=request, response=response, body=body)
if response.status_code == 401:
return exceptions.AuthenticationError(err_msg, request=request, response=response, body=body)
if response.status_code == 403:
return exceptions.PermissionDeniedError(err_msg, request=request, response=response, body=body)
if response.status_code == 404:
return exceptions.NotFoundError(err_msg, request=request, response=response, body=body)
if response.status_code == 409:
return exceptions.ConflictError(err_msg, request=request, response=response, body=body)
if response.status_code == 422:
return exceptions.UnprocessableEntityError(err_msg, request=request, response=response, body=body)
if response.status_code == 429:
return exceptions.RateLimitError(err_msg, request=request, response=response, body=body)
if response.status_code >= 500:
return exceptions.InternalServerError(err_msg, request=request, response=response, body=body)
return APIStatusError(err_msg, request=request, response=response, body=body)
) -> _exceptions.APIStatusError:
raise NotImplementedError()

def _remaining_retries(
self,
Expand Down Expand Up @@ -531,12 +513,24 @@ def _process_response(
# in the response, e.g. application/json; charset=utf-8
content_type, *_ = response.headers.get("content-type").split(";")
if content_type != "application/json":
raise ValueError(
f"Expected Content-Type response header to be `application/json` but received {content_type} instead."
)
if self._strict_response_validation:
raise APIResponseValidationError(
response=response,
message=f"Expected Content-Type response header to be `application/json` but received `{content_type}` instead.",
body=response.text,
)

# If the API responds with content that isn't JSON then we just return
# the (decoded) text without performing any parsing so that you can still
# handle the response however you need to.
return response.text # type: ignore

data = response.json()
return self._process_response_data(data=data, cast_to=cast_to, response=response)

try:
return self._process_response_data(data=data, cast_to=cast_to, response=response)
except pydantic.ValidationError as err:
raise APIResponseValidationError(response=response, body=data) from err

def _process_response_data(
self,
Expand Down Expand Up @@ -818,7 +812,7 @@ def _request(
# If the response is streamed then we need to explicitly read the response
# to completion before attempting to access the response text.
err.response.read()
raise self._make_status_error_from_response(request, err.response) from None
raise self._make_status_error_from_response(err.response) from None
except httpx.TimeoutException as err:
if retries > 0:
return self._retry_request(options, cast_to, retries, stream=stream, stream_cls=stream_cls)
Expand All @@ -837,12 +831,7 @@ def _request(
raise MissingStreamClassError()
return stream_cls(cast_to=cast_to, response=response, client=self)

try:
rsp = self._process_response(cast_to=cast_to, options=options, response=response)
except pydantic.ValidationError as err:
raise APIResponseValidationError(request=request, response=response) from err

return rsp
return self._process_response(cast_to=cast_to, options=options, response=response)

def _retry_request(
self,
Expand Down Expand Up @@ -1176,7 +1165,7 @@ async def _request(
# If the response is streamed then we need to explicitly read the response
# to completion before attempting to access the response text.
await err.response.aread()
raise self._make_status_error_from_response(request, err.response) from None
raise self._make_status_error_from_response(err.response) from None
except httpx.ConnectTimeout as err:
if retries > 0:
return await self._retry_request(options, cast_to, retries, stream=stream, stream_cls=stream_cls)
Expand Down Expand Up @@ -1205,12 +1194,7 @@ async def _request(
raise MissingStreamClassError()
return stream_cls(cast_to=cast_to, response=response, client=self)

try:
rsp = self._process_response(cast_to=cast_to, options=options, response=response)
except pydantic.ValidationError as err:
raise APIResponseValidationError(request=request, response=response) from err

return rsp
return self._process_response(cast_to=cast_to, options=options, response=response)

async def _retry_request(
self,
Expand Down
117 changes: 0 additions & 117 deletions src/finch/_base_exceptions.py

This file was deleted.

Loading