自定义exception名称而不是UserLambdaValidationException
我使用Cognito的Pre sign-up
触发器来validation用户注册。 如果某些validation失败,函数将返回一个自定义错误。 客户端只接收UserLambdaValidationException
作为ErrorCode
。
有没有办法接收自定义错误名称?
当前使用样本:
exports.handler = function(event, context, callback) { function AccountAlreadyExistsError(message) { this.name = "AccountAlreadyExistsError"; this.message = message; } AccountAlreadyExistsError.prototype = new Error(); const error = new AccountAlreadyExistsError("Account is in use!"); callback(error); };
我想在我们的客户端,而不是UserLambdaValidationException
AccountAlreadyExistsError
。
我试了一下,并能在客户端得到错误信息。 使用AWS CLI,Nodejs和内置的Cognito UI对其进行testing。 我使用以下方法返回错误:
var error = new Error('something went wrong..!'); callback(error,event);
我得到了错误UserLambdaValidationException: PreSignUp failed with error something went wrong..!
在我所有的客户。 即使callback(error)
工作。