File: _exceptions.py

package info (click to toggle)
hcloud-python 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,396 kB
  • sloc: python: 15,311; makefile: 43; javascript: 3
file content (31 lines) | stat: -rw-r--r-- 745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

from typing import Any


class HCloudException(Exception):
    """There was an error while using the hcloud library"""


class APIException(HCloudException):
    """There was an error while performing an API Request"""

    def __init__(
        self,
        code: int | str,
        message: str,
        details: Any,
        *,
        correlation_id: str | None = None,
    ):
        extras = [str(code)]
        if correlation_id is not None:
            extras.append(correlation_id)

        error = f"{message} ({', '.join(extras)})"

        super().__init__(error)
        self.code = code
        self.message = message
        self.details = details
        self.correlation_id = correlation_id