44Corresponds to TypeScript file: src/server/auth/errors.ts
55"""
66
7- from typing import Dict
7+ from typing import Literal
88
9- from pydantic import ValidationError
9+ from pydantic import BaseModel , ValidationError
10+
11+ ErrorCode = Literal ["invalid_request" , "invalid_client" ]
12+
13+ class ErrorResponse (BaseModel ):
14+ error : ErrorCode
15+ error_description : str
1016
1117
1218class OAuthError (Exception ):
@@ -16,25 +22,17 @@ class OAuthError(Exception):
1622 Corresponds to OAuthError in src/server/auth/errors.ts
1723 """
1824
19- error_code : str = "server_error"
20-
21- def __init__ (self , message : str ):
22- super ().__init__ (message )
23- self .message = message
24-
25- def to_response_object (self ) -> Dict [str , str ]:
26- """Convert error to JSON response object."""
27- return {"error" : self .error_code , "error_description" : self .message }
25+ error_code : ErrorCode
2826
27+ def __init__ (self , error_description : str ):
28+ super ().__init__ (error_description )
29+ self .error_description = error_description
2930
30- class ServerError (OAuthError ):
31- """
32- Server error.
33-
34- Corresponds to ServerError in src/server/auth/errors.ts
35- """
36-
37- error_code = "server_error"
31+ def error_response (self ) -> ErrorResponse :
32+ return ErrorResponse (
33+ error = self .error_code ,
34+ error_description = self .error_description ,
35+ )
3836
3937
4038class InvalidRequestError (OAuthError ):
@@ -57,96 +55,6 @@ class InvalidClientError(OAuthError):
5755 error_code = "invalid_client"
5856
5957
60- class InvalidGrantError (OAuthError ):
61- """
62- Invalid grant error.
63-
64- Corresponds to InvalidGrantError in src/server/auth/errors.ts
65- """
66-
67- error_code = "invalid_grant"
68-
69-
70- class UnauthorizedClientError (OAuthError ):
71- """
72- Unauthorized client error.
73-
74- Corresponds to UnauthorizedClientError in src/server/auth/errors.ts
75- """
76-
77- error_code = "unauthorized_client"
78-
79-
80- class UnsupportedGrantTypeError (OAuthError ):
81- """
82- Unsupported grant type error.
83-
84- Corresponds to UnsupportedGrantTypeError in src/server/auth/errors.ts
85- """
86-
87- error_code = "unsupported_grant_type"
88-
89-
90- class UnsupportedResponseTypeError (OAuthError ):
91- """
92- Unsupported response type error.
93-
94- Corresponds to UnsupportedResponseTypeError in src/server/auth/errors.ts
95- """
96-
97- error_code = "unsupported_response_type"
98-
99-
100- class InvalidScopeError (OAuthError ):
101- """
102- Invalid scope error.
103-
104- Corresponds to InvalidScopeError in src/server/auth/errors.ts
105- """
106-
107- error_code = "invalid_scope"
108-
109-
110- class AccessDeniedError (OAuthError ):
111- """
112- Access denied error.
113-
114- Corresponds to AccessDeniedError in src/server/auth/errors.ts
115- """
116-
117- error_code = "access_denied"
118-
119-
120- class TemporarilyUnavailableError (OAuthError ):
121- """
122- Temporarily unavailable error.
123-
124- Corresponds to TemporarilyUnavailableError in src/server/auth/errors.ts
125- """
126-
127- error_code = "temporarily_unavailable"
128-
129-
130- class InvalidTokenError (OAuthError ):
131- """
132- Invalid token error.
133-
134- Corresponds to InvalidTokenError in src/server/auth/errors.ts
135- """
136-
137- error_code = "invalid_token"
138-
139-
140- class InsufficientScopeError (OAuthError ):
141- """
142- Insufficient scope error.
143-
144- Corresponds to InsufficientScopeError in src/server/auth/errors.ts
145- """
146-
147- error_code = "insufficient_scope"
148-
149-
15058def stringify_pydantic_error (validation_error : ValidationError ) -> str :
15159 return "\n " .join (
15260 f"{ '.' .join (str (loc ) for loc in e ['loc' ])} : { e ['msg' ]} "
0 commit comments