Add NeonAPIError exception and update exception handling

This commit is contained in:
2024-02-03 10:10:46 -05:00
parent dfa261b692
commit 3673f76031
3 changed files with 10 additions and 8 deletions
+1 -3
View File
@@ -1,5 +1,6 @@
from .client import NeonAPI
from .__version__ import __version__
from .exceptions import NeonAPIError
def from_environ():
@@ -8,6 +9,3 @@ def from_environ():
def from_token(token):
return NeonAPI.from_token(token)
from .client import *
+8 -4
View File
@@ -2,12 +2,13 @@ import os
import typing as t
from datetime import datetime
from functools import wraps
import urllib.parse
import requests
from . import schema
from .utils import compact_mapping, to_iso8601
from .exceptions import NeonClientException
from .exceptions import NeonAPIException
__VERSION__ = "0.1.0"
@@ -18,7 +19,10 @@ ENABLE_PYDANTIC = True
def returns_model(model, is_array=False):
"""Decorator that returns a model instance."""
"""Decorator that returns a Pydantic model.
If Pydantic is not enabled, the original return value is returned.
"""
def decorator(func):
@wraps(func)
@@ -95,14 +99,14 @@ class NeonAPI:
try:
r.raise_for_status()
except requests.exceptions.HTTPError:
raise NeonClientException(r.text)
raise NeonAPIException(r.text)
return r.json()
def _url_join(self, *args):
"""Join a list of URL components into a single URL."""
return "/".join(args)
return "/".join(*args)
@classmethod
def from_environ(cls):
+1 -1
View File
@@ -1,5 +1,5 @@
from requests.exceptions import HTTPError
class NeonClientException(HTTPError):
class NeonAPIException(HTTPError):
pass