Skip to content

exceptions

pixel_client.exceptions

PixelBadRequestError

Bases: Exception

Exception raised when a bad request is made to the Pixel API.

Source code in src/pixel_client/exceptions.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class PixelBadRequestError(Exception):
    """Exception raised when a bad request is made to the Pixel API."""

    def __init__(
        self,
        response_json: dict,
        status_code: int,
        method: str,
        url: str,
        request_id: str | None = None,
        body: str | None = None,
    ):
        # Pretty print the response json
        self.json_resp_msg = json.dumps(response_json, indent=4)
        self.status_code = status_code
        self.method = method
        self.url = url
        self.body = body
        self.message = f"Bad request {self.status_code} for {self.method} {self.url} (request ID: {request_id})"
        if body:
            self.message += f"\nPayload:\n{self.body}"
        self.message += f"\nResponse: \n{self.json_resp_msg}"
        # Catch validation errors from pydantic
        super().__init__(self.message)

json_resp_msg instance-attribute

json_resp_msg = json.dumps(response_json, indent=4)

status_code instance-attribute

status_code = status_code

method instance-attribute

method = method

url instance-attribute

url = url

body instance-attribute

body = body

message instance-attribute

message = f"Bad request {self.status_code} for {self.method} {self.url} (request ID: {request_id})"

__init__

__init__(
    response_json: dict,
    status_code: int,
    method: str,
    url: str,
    request_id: str | None = None,
    body: str | None = None,
)
Source code in src/pixel_client/exceptions.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def __init__(
    self,
    response_json: dict,
    status_code: int,
    method: str,
    url: str,
    request_id: str | None = None,
    body: str | None = None,
):
    # Pretty print the response json
    self.json_resp_msg = json.dumps(response_json, indent=4)
    self.status_code = status_code
    self.method = method
    self.url = url
    self.body = body
    self.message = f"Bad request {self.status_code} for {self.method} {self.url} (request ID: {request_id})"
    if body:
        self.message += f"\nPayload:\n{self.body}"
    self.message += f"\nResponse: \n{self.json_resp_msg}"
    # Catch validation errors from pydantic
    super().__init__(self.message)

PixelUploadJobError

Bases: Exception

Exception raised when an upload job fails.

Source code in src/pixel_client/exceptions.py
30
31
32
33
34
35
36
37
38
39
40
41
42
class PixelUploadJobError(Exception):
    """
    Exception raised when an upload job fails.
    """

    def __init__(self, job_id: int, status: str, detail: str):
        self.job_id = job_id
        self.detail = detail
        self.status = status
        message = (
            f"Upload job {job_id} failed with status '{status}', detail: \n{detail}"
        )
        super().__init__(message)

job_id instance-attribute

job_id = job_id

detail instance-attribute

detail = detail

status instance-attribute

status = status

__init__

__init__(job_id: int, status: str, detail: str)
Source code in src/pixel_client/exceptions.py
35
36
37
38
39
40
41
42
def __init__(self, job_id: int, status: str, detail: str):
    self.job_id = job_id
    self.detail = detail
    self.status = status
    message = (
        f"Upload job {job_id} failed with status '{status}', detail: \n{detail}"
    )
    super().__init__(message)

PixelMultipleUploadJobError

Bases: Exception

Exception raised when multiple upload jobs fail.

Source code in src/pixel_client/exceptions.py
45
46
47
48
49
50
51
52
53
54
class PixelMultipleUploadJobError(Exception):
    """
    Exception raised when multiple upload jobs fail.
    """

    def __init__(self, errors: list[PixelUploadJobError]):
        self.errors = errors
        error_messages = "\n".join(str(e) for e in errors)
        message = f"Multiple upload jobs failed:\n{error_messages}"
        super().__init__(message)

errors instance-attribute

errors = errors

__init__

__init__(errors: list[PixelUploadJobError])
Source code in src/pixel_client/exceptions.py
50
51
52
53
54
def __init__(self, errors: list[PixelUploadJobError]):
    self.errors = errors
    error_messages = "\n".join(str(e) for e in errors)
    message = f"Multiple upload jobs failed:\n{error_messages}"
    super().__init__(message)

PixelAccessUpdateError

Bases: Exception

Exception raised when an access change that spans several requests partly fails.

Every independent request is attempted before this is raised, so succeeded lists the changes that were applied and failed the ones that were not, each with the error the API returned.

Attributes:

Name Type Description
succeeded

The changes that were applied.

failed

The changes that were not applied, paired with their error.

result

The object created by the call (a user or group), if it got that far.

Source code in src/pixel_client/exceptions.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class PixelAccessUpdateError(Exception):
    """
    Exception raised when an access change that spans several requests partly fails.

    Every independent request is attempted before this is raised, so
    `succeeded` lists the changes that were applied and `failed` the ones that
    were not, each with the error the API returned.

    Attributes:
        succeeded: The changes that were applied.
        failed: The changes that were not applied, paired with their error.
        result: The object created by the call (a user or group), if it got that far.
    """

    def __init__(
        self,
        succeeded: list[dict],
        failed: list[tuple[dict, Exception]],
        result: dict | None = None,
    ):
        self.succeeded = succeeded
        self.failed = failed
        self.result = result
        lines = [
            f"- {change.get('action', 'change')} {change.get('principal_kind', '')} "
            f"{change.get('principal_id', '')} on {change.get('resource', '')}: {error}"
            for change, error in failed
        ]
        message = (
            f"{len(failed)} access change(s) failed, {len(succeeded)} succeeded:\n"
            + "\n".join(lines)
        )
        super().__init__(message)

succeeded instance-attribute

succeeded = succeeded

failed instance-attribute

failed = failed

result instance-attribute

result = result

__init__

__init__(
    succeeded: list[dict],
    failed: list[tuple[dict, Exception]],
    result: dict | None = None,
)
Source code in src/pixel_client/exceptions.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def __init__(
    self,
    succeeded: list[dict],
    failed: list[tuple[dict, Exception]],
    result: dict | None = None,
):
    self.succeeded = succeeded
    self.failed = failed
    self.result = result
    lines = [
        f"- {change.get('action', 'change')} {change.get('principal_kind', '')} "
        f"{change.get('principal_id', '')} on {change.get('resource', '')}: {error}"
        for change, error in failed
    ]
    message = (
        f"{len(failed)} access change(s) failed, {len(succeeded)} succeeded:\n"
        + "\n".join(lines)
    )
    super().__init__(message)