-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgleanerror.py
More file actions
40 lines (29 loc) · 1.27 KB
/
gleanerror.py
File metadata and controls
40 lines (29 loc) · 1.27 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
40
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
import httpx
from typing import Optional
from dataclasses import dataclass
from glean.api_client.errors import GleanBaseError
MAX_MESSAGE_LEN = 10_000
@dataclass(unsafe_hash=True)
class GleanError(GleanBaseError):
"""The fallback error class if no more specific error class is matched."""
def __init__(
self, message: str, raw_response: httpx.Response, body: Optional[str] = None
):
body_display = body or raw_response.text or '""'
if message:
message += ": "
message += f"Status {raw_response.status_code}"
headers = raw_response.headers
content_type = headers.get("content-type", '""')
if content_type != "application/json":
if " " in content_type:
content_type = f'"{content_type}"'
message += f" Content-Type {content_type}"
if len(body_display) > MAX_MESSAGE_LEN:
truncated = body_display[:MAX_MESSAGE_LEN]
remaining = len(body_display) - MAX_MESSAGE_LEN
body_display = f"{truncated}...and {remaining} more chars"
message += f". Body: {body_display}"
message = message.strip()
super().__init__(message, raw_response, body)