Untitled
unknown
plain_text
3 months ago
1.4 kB
3
Indexable
import json from typing import Dict, Any class ValidationError(Exception): pass class NotFoundError(Exception): pass def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]: try: body = json.loads(event.get('body', '{}')) if 'first_name' not in body: raise ValidationError("Missing required parameter: first_name") # Your business logic here result = process_data(body) return { "statusCode": 200, "body": json.dumps({"data": result}) } except ValidationError as e: return { "statusCode": 400, "body": json.dumps({ "error": { "type": "ValidationError", "message": str(e) } }) } except NotFoundError as e: return { "statusCode": 404, "body": json.dumps({ "error": { "type": "NotFoundError", "message": str(e) } }) } except Exception as e: # Catch unexpected errors return { "statusCode": 500, "body": json.dumps({ "error": { "type": "InternalError", "message": "Internal server error" } }) }
Editor is loading...
Leave a Comment