@@ -91,7 +91,7 @@ def has_errors(self) -> bool:
9191
9292 def get_errors (self ) -> dict [str , Any ] | None :
9393 """Get global errors if any."""
94- return {"resource_errors " : self ._resource_errors .copy (), "error" : self ._error }
94+ return {"resources " : self ._resource_errors .copy (), "error" : self ._error }
9595
9696 def get_error (self ) -> dict [str , str ] | None :
9797 """Get global error if any."""
@@ -467,7 +467,7 @@ def my_tool(access_ctx: AccessContext, ctx: Context, user_id: str):
467467 @provider.grant("https://api.example.com")
468468 async def my_async_tool(access_ctx: AccessContext, ctx: Context, user_id: str):
469469 if access_ctx.has_errors():
470- return {"error ": "Token exchange failed"}
470+ return {"message ": "Token exchange failed"}
471471 token = access_ctx.access("https://api.example.com").access_token
472472 # Async API call
473473 return f"Async data for {user_id}"
@@ -606,37 +606,37 @@ async def wrapper(*args, **kwargs) -> Any:
606606 _keycardai_auth_info = _extract_auth_info_from_context (* args , ** kwargs )
607607 if not _keycardai_auth_info :
608608 _set_error ({
609- "error " : "No request authentication information available. Ensure the provider is correctly configured." ,
609+ "message " : "No request authentication information available. Ensure the provider is correctly configured." ,
610610 }, None , _access_ctx )
611611 return await _call_func (_is_async_func , func , * args , ** kwargs )
612612
613613 if not _keycardai_auth_info ["access_token" ]:
614614 _set_error ({
615- "error " : "No authentication token available. Please ensure you're properly authenticated." ,
615+ "message " : "No authentication token available. Please ensure you're properly authenticated." ,
616616 }, None , _access_ctx )
617617 return await _call_func (_is_async_func , func , * args , ** kwargs )
618618 except Exception as e :
619619 _set_error ({
620- "error " : "Failed to get access token from context. Ensure the Context parameter is properly annotated." ,
620+ "message " : "Failed to get access token from context. Ensure the Context parameter is properly annotated." ,
621621 "raw_error" : str (e ),
622622 }, None , _access_ctx )
623623 return await _call_func (_is_async_func , func , * args , ** kwargs )
624624 _client = None
625625 if self .enable_multi_zone and not _keycardai_auth_info ["zone_id" ]:
626626 _set_error ({
627- "error " : "Zone ID is required for multi-zone configuration but not found in request." ,
627+ "message " : "Zone ID is required for multi-zone configuration but not found in request." ,
628628 }, None , _access_ctx )
629629 return await _call_func (_is_async_func , func , * args , ** kwargs )
630630 try :
631631 _client = await self ._get_or_create_client (_keycardai_auth_info )
632632 if _client is None :
633633 _set_error ({
634- "error " : "OAuth client not available. Server configuration issue." ,
634+ "message " : "OAuth client not available. Server configuration issue." ,
635635 }, None , _access_ctx )
636636 return await _call_func (_is_async_func , func , * args , ** kwargs )
637637 except Exception as e :
638638 _set_error ({
639- "error " : "Failed to initialize OAuth client. Server configuration issue." ,
639+ "message " : "Failed to initialize OAuth client. Server configuration issue." ,
640640 "raw_error" : str (e ),
641641 }, None , _access_ctx )
642642 return await _call_func (_is_async_func , func , * args , ** kwargs )
@@ -666,15 +666,19 @@ async def wrapper(*args, **kwargs) -> Any:
666666 _token_response = await _client .exchange_token (_token_exchange_request )
667667 _access_tokens [resource ] = _token_response
668668 except Exception as e :
669- _error_message = f"Token exchange failed for { resource } "
669+ _error_dict : dict [str , str ] = {
670+ "message" : f"Token exchange failed for { resource } " ,
671+ }
670672 if self .enable_private_key_identity and _keycardai_auth_info .get ("resource_client_id" ):
671- _error_message += f" with client id: { _keycardai_auth_info ['resource_client_id' ]} "
672- _error_message += f": { e } "
673-
674- _set_error ({
675- "error" : _error_message ,
676- "raw_error" : str (e ),
677- }, resource , _access_ctx )
673+ _error_dict ["message" ] += f" with client id: { _keycardai_auth_info ['resource_client_id' ]} "
674+ if hasattr (e , "error" ):
675+ _error_dict ["code" ] = e .error
676+ if hasattr (e , "error_description" ) and e .error_description :
677+ _error_dict ["description" ] = e .error_description
678+ if not hasattr (e , "error" ):
679+ _error_dict ["raw_error" ] = str (e )
680+
681+ _set_error (_error_dict , resource , _access_ctx )
678682
679683 # Set successful tokens on the existing access_context (preserves any resource errors)
680684 _access_ctx .set_bulk_tokens (_access_tokens )
0 commit comments