The returned errorType represents the 'name' property set on the error.
So the following code:
var error = new Error('Its an error!');
error.name = 'TheName';
context.fail(error);
Results in the following response from Lambda to API Gateway:
{
"errorMessage": "Its an error!",
"errorType": "TheName",
"stackTrace": [
"exports.handler (/var/task/index.js:10:21)"
]
}
Unfortunately, it seems the API Gateway only matches the Error Regex to the 'errorMessage' property. At least based on my attempts and what I've read so-far. So setting the error type won't help if you are trying to map to status codes. (as mentioned in the comments)
One way to get a little bit of both worlds is to "toString()" your error when calling context.fail. This will format your error message as "[name]:[error message]".
You can then match your API Gateway Error Regex to the specific error "name" property.
So calling:
var error = new Error('Its an error!');
error.name = 'TheName';
context.fail(error.toString());
When API Gateway Regex mapped to status 500:
TheName.*
Results in the following status 500 API Gateway response:
{
"errorMessage": "TheName: Its an error!"
}