Complete the code to define a fallback method for a microservice call.
def get_user_data(user_id): try: return call_remote_service(user_id) except Exception: return [1]()
The fallback method fallback_response is called when the remote service fails.
Complete the code to implement a fallback pattern using a circuit breaker.
if circuit_breaker.is_open(): response = [1]() else: response = call_remote_service()
When the circuit breaker is open, the system uses the fallback response to avoid calling the failing service.
Fix the error in the fallback implementation to handle service failure gracefully.
def fetch_data(): try: data = call_service() except Exception: data = [1] return data
Returning None in the except block is a safe fallback to indicate failure without crashing.
Fill both blanks to implement a fallback with a timeout and default response.
try: response = call_service(timeout=[1]) except TimeoutError: response = [2]()
The timeout is set to 5 seconds, and fallback_response is used if a timeout occurs.
Fill all three blanks to create a fallback pattern with logging and default data.
def get_data(): try: return call_service() except Exception as e: [1](f"Service failed: {e}") return [2]() fallback_response = lambda: [3]
Errors are logged with log_error, fallback method fallback_response is called, which returns default data.