I understood I can assign http status according to regex matched on response from lambda function.
For example I have API call to login user to Cognito which throws error on invalid credentials with code NotAuthorizedException
and message Incorrect username or password.
and I wonder how to categorize it as error 401.
I added prefix [401]
to the message and APIG settings below ensures that the API call really ends with code 401 and message {"message": "[401] Incorrect username or password.","code": "NotAuthorizedException"}
.
"responses": {
".*401.*": {
"statusCode": "401",
"responseModels": {},
"responseTemplates": {
"application/json": "{\"message\": \"$input.path('$.errorMessage')\",\"code\": \"$input.path('$.errorType')\"}"
}
}
}
But I would be happier if that [401]
prefix isn’t propagated to the user (so that he gets only {"message": "Incorrect username or password.","code": "NotAuthorizedException"}
. Is it possible to remove it from the message afterwards or somehow identify the error without altering the message?