-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.py
More file actions
39 lines (26 loc) · 1.09 KB
/
Copy pathcustom.py
File metadata and controls
39 lines (26 loc) · 1.09 KB
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
32
33
34
35
36
37
38
39
"""Custom exceptions for the sample_python_app project."""
class HTTPTimeoutError(Exception):
"""Raised when an HTTP request times out."""
def __init__(self, message: str) -> None:
"""Initialize the HTTPTimeoutError with a message."""
super().__init__(message)
class NetworkError(Exception):
"""Raised when a network-level error occurs.
(connection refused, DNS failure, etc.).
"""
def __init__(self, message: str) -> None:
"""Initialize the NetworkError with a message."""
super().__init__(message)
class ServiceError(Exception):
"""Raised when the HTTP response returns an error status (4xx or 5xx)."""
def __init__(self, status_code: int, body: str | None = None) -> None:
"""Initialize the ServiceError with status code and optional response body."""
self.status_code = status_code
self.body = body
msg = f"Service returned status {status_code}"
if body:
msg += f": {body}"
super().__init__(msg)
class AppError(Exception):
"""Base exception for the application."""
pass