source-code_snippets_6_py
import traceback
try:
# simulate an error
raise Exception("Oops! Something went wrong.");
except Exception as e:
return {
"status": 418,
"body": {
"error": {
"message": e,
"stack": traceback.format_exc(),
},
},
"headers": {
"X-Custom-Header": "I am a custom header",
},
};
}