Source code for psnawp_api.core.psnawp_exceptions
"""Provide exception classes for the psnawp package."""
import json
from typing import Any
[docs]
class PSNAWPError(Exception):
"""Base Exception for all PSNAWP Exceptions."""
[docs]
def __init__(
self,
response: str,
) -> None:
"""Initialize the exception."""
self.code: int | None = None
self.message: str | None = None
self.reference_id: str | None = None
try:
error: dict[str, dict[str, Any]] = json.loads(response)
except json.JSONDecodeError:
pass
else:
err = error.get("error", {})
self.reference_id = err.get("referenceId")
self.code = err.get("code")
self.message = err.get("message")
super().__init__(self.message or response)
[docs]
class PSNAWPServerError(PSNAWPError):
"""Exception raised if there is a problem at the server."""
[docs]
class PSNAWPClientError(PSNAWPError):
"""Exception raised if there is a problem at the client."""
[docs]
class PSNAWPAuthenticationError(PSNAWPClientError):
"""Exception for authentication related errors."""
[docs]
class PSNAWPBadRequestError(PSNAWPClientError):
"""Exception raised if bad request is made to the endpoint."""
[docs]
class PSNAWPIllegalArgumentError(PSNAWPClientError):
"""Exception raised if user gave wrong input to a function."""
[docs]
class PSNAWPUnauthorizedError(PSNAWPClientError):
"""Exception for accessing an action is not allowed due to missing the right authorization."""
[docs]
class PSNAWPInvalidTokenError(PSNAWPClientError):
"""Exception raised if user gave unparsable npsso token string."""
[docs]
class PSNAWPForbiddenError(PSNAWPClientError):
"""Exception for accessing an action is not allowed due to insufficient rights to a resource."""
[docs]
class PSNAWPNotFoundError(PSNAWPClientError):
"""Exception raised if resource not found."""
[docs]
class PSNAWPNotAllowedError(PSNAWPClientError):
"""Exception raised if resource doesn't support this method."""
[docs]
class PSNAWPTooManyRequestsError(PSNAWPClientError):
"""Exception raised if client sends too many requests."""