-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: error subspecification * chore: version bump
- Loading branch information
Showing
15 changed files
with
206 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from pocketbase.client import PocketBase | ||
from pocketbase.models.errors import PocketbaseError | ||
from pocketbase.models.errors import PocketBaseError | ||
from pocketbase.utils.types import FileUpload | ||
|
||
__all__ = ["PocketBase", "FileUpload", "PocketbaseError"] | ||
__all__ = ["PocketBase", "FileUpload", "PocketBaseError"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,50 @@ | ||
from typing import Any | ||
|
||
from httpx import Response | ||
|
||
class PocketbaseError(Exception): | ||
|
||
class PocketBaseError(Exception): | ||
def __init__(self, url: str, status: int, data: Any) -> None: | ||
self.url = url | ||
self.status = status | ||
self.data = data | ||
|
||
def __repr__(self) -> str: | ||
return f"PocketbaseError(url={self.url},status={self.status},data={self.data})" | ||
return f"{self.__class__.__name__}(url={self.url},status={self.status},data={self.data})" | ||
|
||
__str__ = __repr__ | ||
|
||
@classmethod | ||
def raise_for_status(cls, response: Response) -> None: | ||
if response.status_code == 400: | ||
raise PocketBaseBadRequestError(str(response.url), response.status_code, response.json()) | ||
elif response.status_code == 401: | ||
raise PocketBaseUnauthorizedError(str(response.url), response.status_code, response.json()) | ||
elif response.status_code == 403: | ||
raise PocketBaseForbiddenError(str(response.url), response.status_code, response.json()) | ||
elif response.status_code == 404: | ||
raise PocketBaseNotFoundError(str(response.url), response.status_code, response.json()) | ||
elif response.status_code == 500: | ||
raise PocketBaseServerError(str(response.url), response.status_code, response.json()) | ||
elif response.status_code >= 400: | ||
raise PocketBaseError(str(response.url), response.status_code, response.json()) | ||
|
||
|
||
class PocketBaseNotFoundError(PocketBaseError): | ||
pass | ||
|
||
|
||
class PocketBaseBadRequestError(PocketBaseError): | ||
pass | ||
|
||
|
||
class PocketBaseUnauthorizedError(PocketBaseError): | ||
pass | ||
|
||
|
||
class PocketBaseForbiddenError(PocketBaseError): | ||
pass | ||
|
||
|
||
class PocketBaseServerError(PocketBaseError): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters