MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeWiki / wrap_api_call

Function wrap_api_call

codewiki/cli/utils/api_errors.py:114–139  ·  view source on GitHub ↗

Wrap an API call with error handling. Args: func: Function to call *args: Positional arguments fail_fast: Whether to raise on error (default: True) context: Optional context for error message **kwargs: Keyword arguments Returns:

(func, *args, fail_fast: bool = True, context: Optional[str] = None, **kwargs)

Source from the content-addressed store, hash-verified

112
113
114def wrap_api_call(func, *args, fail_fast: bool = True, context: Optional[str] = None, **kwargs):
115 """
116 Wrap an API call with error handling.
117
118 Args:
119 func: Function to call
120 *args: Positional arguments
121 fail_fast: Whether to raise on error (default: True)
122 context: Optional context for error message
123 **kwargs: Keyword arguments
124
125 Returns:
126 Function result
127
128 Raises:
129 APIError: If API call fails and fail_fast is True
130 """
131 try:
132 return func(*args, **kwargs)
133 except Exception as e:
134 api_error = APIErrorHandler.handle_api_error(e, context=context, fail_fast=fail_fast)
135 if fail_fast:
136 raise api_error
137 else:
138 APIErrorHandler.display_api_error(api_error)
139 return None
140

Callers

nothing calls this directly

Calls 2

handle_api_errorMethod · 0.80
display_api_errorMethod · 0.80

Tested by

no test coverage detected