I'm building a response template for an AWS API Gateway endpoint to handle errors. The incoming JSON error message looks like one of the following:
{
"__type": "UserNotFoundException",
"message": "User does not exist."
}
{
"__type": "NotAuthorizedException",
"message": "Incorrect username or password."
}
{
"__type": "NotAuthorizedException",
"message": "Password attempts exceeded"
}
My VTL mapping template looks like:
#set($inputRoot = $input.path('$'))
#set($unf = "UserNotFoundException")
#set($nae = "NotAuthorizedException")
#set($type =$input.json('$.__type'))
#if($type == $unf)
{
"__type": "UserNotFoundException",
"message": $input.json('$.message'),
"referenceCode": "UNF0000"
}
#elseif($type == $nae)
{
"__type": "NotAuthorizedException",
"message": $input.json('$.message'),
"referenceCode": "NAE0000"
}
#else
{
"__type": $input.json('$.__type'),
"message": $input.json('$.message'),
"referenceCode": "FAIL0000"
}
#end
No matter what input I use to trigger my 400 error response, it falls through to my catch-all else case. The __type that is output in my else case matches one of the other conditionals, so I'm confused why they aren't catching it. Any help would be appreciated! (I'm new to AWS and VTL)