Complete the code to return a 404 error when a resource is not found.
if resource is None: return [1](404, 'Resource not found')
Using abort with a 404 status code sends a consistent error response to the client.
Complete the code to return a JSON error message with status 400.
return [1]({'error': 'Bad request'}), 400
jsonify formats the dictionary as JSON and sets the correct headers.
Fix the error in the code to send a consistent 500 error response.
try: process_request() except Exception as e: return [1]({'error': str(e)}), 500
Using jsonify ensures the error message is sent as JSON with the correct status code.
Fill both blanks to create a consistent error handler for 403 Forbidden errors.
@app.errorhandler([1]) def forbidden_error(error): return [2]({'error': 'Forbidden'}), 403
The decorator uses the 403 status code, and jsonify sends the JSON error response.
Fill all three blanks to create a consistent error response with a custom message and status code.
def error_response(message, code): response = [1]({'error': message}) response.status_code = [2] return response return error_response([3], 401)
jsonify creates the JSON response, 401 sets the status code, and the message is a string describing the error.