# Raising Exceptions from Lambda to API Gateway Caller
> [!META]- Inline Metadata
> [status:: boat]
> [source::]
> [tags:: #note/evergreen #state/boat #concepts/aws/lambda #concepts/aws/api-gateway ]
> [up:: [[AWS Lambda MOC]] [[AWS API Gateway MOC]]]
You can send exception feedback from a Lambda to an API Gateway API either by raising a Python exception and handling it via a mapping template, or return a specific set of values from the main handler function.
## Returning from the Handler Function
You can return a dictionary that includes at least:
- the desired status code
- the message body (JSONified)
- and whether or not the body is base64 encoded
```python
return {
"statusCode": 404,
"body": simplejson.dumps(
f"User {username} not found"
),
"isBase64Encoded": False,
}
```
## Raising an Exceptions
Using a [mapping template](https://aws.amazon.com/blogs/compute/error-handling-patterns-in-amazon-api-gateway-and-aws-lambda/) allows you to simply use regex to associate an error message from a plain Python exception with a certain HTTP code. I don't have any examples because I haven't done it, preferring the [[Raising Exceptions from Lambda to API Gateway Caller#Returning from the Handler Function|previous method]].