Module signals_notebook.exceptions

Expand source code
from typing import List

import requests
from pydantic import BaseModel, parse_obj_as, PydanticValueError


class ErrorBody(BaseModel):
    status: str
    code: str
    title: str = ''
    detail: str = ''


class ErrorResponse(BaseModel):
    errors: List[ErrorBody]


class SignalsNotebookError(Exception):
    def __init__(self, response: requests.Response):
        """Handle Signals Notebook API errors

        Args:
            response: Response object, which contains a server's response to an HTTP request.
        """
        self.parsed_response = parse_obj_as(ErrorResponse, response.json())

    def __str__(self) -> str:
        error = self.parsed_response.errors[0]
        return (
            f'<SignalsNotebookError status={error.status} code={error.code}> title={error.title} detail={error.detail}>'
        )


class EIDError(PydanticValueError):
    msg_template = 'incorrect EID value: "{value}"'

Classes

class EIDError (**ctx: Any)

Inappropriate argument value (of correct type).

Expand source code
class EIDError(PydanticValueError):
    msg_template = 'incorrect EID value: "{value}"'

Ancestors

  • pydantic.errors.PydanticValueError
  • pydantic.errors.PydanticErrorMixin
  • builtins.ValueError
  • builtins.Exception
  • builtins.BaseException

Class variables

var msg_template
class ErrorBody (**data: Any)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Expand source code
class ErrorBody(BaseModel):
    status: str
    code: str
    title: str = ''
    detail: str = ''

Ancestors

  • pydantic.main.BaseModel
  • pydantic.utils.Representation

Class variables

var code : str
var detail : str
var status : str
var title : str
class ErrorResponse (**data: Any)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

Expand source code
class ErrorResponse(BaseModel):
    errors: List[ErrorBody]

Ancestors

  • pydantic.main.BaseModel
  • pydantic.utils.Representation

Class variables

var errors : List[ErrorBody]
class SignalsNotebookError (response: requests.models.Response)

Common base class for all non-exit exceptions.

Handle Signals Notebook API errors

Args

response
Response object, which contains a server's response to an HTTP request.
Expand source code
class SignalsNotebookError(Exception):
    def __init__(self, response: requests.Response):
        """Handle Signals Notebook API errors

        Args:
            response: Response object, which contains a server's response to an HTTP request.
        """
        self.parsed_response = parse_obj_as(ErrorResponse, response.json())

    def __str__(self) -> str:
        error = self.parsed_response.errors[0]
        return (
            f'<SignalsNotebookError status={error.status} code={error.code}> title={error.title} detail={error.detail}>'
        )

Ancestors

  • builtins.Exception
  • builtins.BaseException