-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy patherrors.py
More file actions
161 lines (99 loc) · 3.23 KB
/
errors.py
File metadata and controls
161 lines (99 loc) · 3.23 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"""
OAuth error classes for MCP authorization.
Corresponds to TypeScript file: src/server/auth/errors.ts
"""
from typing import TypedDict
from pydantic import ValidationError
class OAuthErrorResponse(TypedDict):
"""OAuth error response format."""
error: str
error_description: str
class OAuthError(Exception):
"""
Base class for all OAuth errors.
Corresponds to OAuthError in src/server/auth/errors.ts
"""
error_code: str = "server_error"
def __init__(self, message: str):
super().__init__(message)
self.message = message
def to_response_object(self) -> OAuthErrorResponse:
"""Convert error to JSON response object."""
return {"error": self.error_code, "error_description": self.message}
class ServerError(OAuthError):
"""
Server error.
Corresponds to ServerError in src/server/auth/errors.ts
"""
error_code = "server_error"
class InvalidRequestError(OAuthError):
"""
Invalid request error.
Corresponds to InvalidRequestError in src/server/auth/errors.ts
"""
error_code = "invalid_request"
class InvalidClientError(OAuthError):
"""
Invalid client error.
Corresponds to InvalidClientError in src/server/auth/errors.ts
"""
error_code = "invalid_client"
class InvalidGrantError(OAuthError):
"""
Invalid grant error.
Corresponds to InvalidGrantError in src/server/auth/errors.ts
"""
error_code = "invalid_grant"
class UnauthorizedClientError(OAuthError):
"""
Unauthorized client error.
Corresponds to UnauthorizedClientError in src/server/auth/errors.ts
"""
error_code = "unauthorized_client"
class UnsupportedGrantTypeError(OAuthError):
"""
Unsupported grant type error.
Corresponds to UnsupportedGrantTypeError in src/server/auth/errors.ts
"""
error_code = "unsupported_grant_type"
class UnsupportedResponseTypeError(OAuthError):
"""
Unsupported response type error.
Corresponds to UnsupportedResponseTypeError in src/server/auth/errors.ts
"""
error_code = "unsupported_response_type"
class InvalidScopeError(OAuthError):
"""
Invalid scope error.
Corresponds to InvalidScopeError in src/server/auth/errors.ts
"""
error_code = "invalid_scope"
class AccessDeniedError(OAuthError):
"""
Access denied error.
Corresponds to AccessDeniedError in src/server/auth/errors.ts
"""
error_code = "access_denied"
class TemporarilyUnavailableError(OAuthError):
"""
Temporarily unavailable error.
Corresponds to TemporarilyUnavailableError in src/server/auth/errors.ts
"""
error_code = "temporarily_unavailable"
class InvalidTokenError(OAuthError):
"""
Invalid token error.
Corresponds to InvalidTokenError in src/server/auth/errors.ts
"""
error_code = "invalid_token"
class InsufficientScopeError(OAuthError):
"""
Insufficient scope error.
Corresponds to InsufficientScopeError in src/server/auth/errors.ts
"""
error_code = "insufficient_scope"
def stringify_pydantic_error(validation_error: ValidationError) -> str:
return "\n".join(
f"{'.'.join(str(loc) for loc in e['loc'])}: {e['msg']}"
for e in validation_error.errors()
)