Javascript 如何更改环回4中有关密码长度的HTTP错误?

Javascript 如何更改环回4中有关密码长度的HTTP错误?,javascript,http-error,loopback4,Javascript,Http Error,Loopback4,我正在使用环回4身份验证,我有这个凭证模式。 在我的register方法中,当给出少于8个字符的密码时,我会得到这个http错误响应。 我试图避免响应中的错误消息,即密码应少于8个字符,而是使用http错误响应进行响应,而不包含该详细信息。如何用自定义错误替换此默认错误 我试过这样的东西 if (credential.password.length < 8) { throw new HttpErrors.NotFound; } if(credential.password.

我正在使用环回4身份验证,我有这个凭证模式。 在我的register方法中,当给出少于8个字符的密码时,我会得到这个http错误响应。 我试图避免响应中的错误消息,即密码应少于8个字符,而是使用http错误响应进行响应,而不包含该详细信息。如何用自定义错误替换此默认错误

我试过这样的东西

if (credential.password.length < 8) {
      throw new HttpErrors.NotFound;
} 
if(credential.password.length<8){
抛出新的HttpErrors.NotFound;
} 
在register方法中,但它不起作用。 我可以删除模式中的minLength limit 8,但我希望在这种情况下得到错误响应

export const CredentialsSchema = {
  type: 'object',
  required: ['email', 'password'],
  properties: {
    email: {
      type: 'string',
      format: 'email',
   },
   password: {
     type: 'string',
     minLength: 8,
   },
  },
};


async register(
@requestBody() credential: CredentialPassword,
): Promise<AccessToken> {
return this.userRegistration(credential);
}


{
"error": {
"statusCode": 422,
"name": "UnprocessableEntityError",
"message": "The request body is invalid. See error object `details` property for more info.",
"code": "VALIDATION_FAILED",
"details": [
  {
    "path": ".password",
    "code": "minLength",
    "message": "should NOT be shorter than 8 characters",
    "info": {
      "limit": 8
    }
  }]
 }
}
export const credentialschema={
类型:“对象”,
必需:[“电子邮件”,“密码”],
特性:{
电邮:{
键入:“字符串”,
格式:“电子邮件”,
},
密码:{
键入:“字符串”,
最小长度:8,
},
},
};
异步寄存器(
@requestBody()凭据:CredentialPassword,
):承诺{
返回此.userRegistration(凭证);
}
{
“错误”:{
“状态代码”:422,
“名称”:“UnprocessableEntityError”,
“消息”:“请求正文无效。有关详细信息,请参阅错误对象`details`属性。”,
“代码”:“验证失败”,
“详情”:[
{
“路径”:“.password”,
“代码”:“最小长度”,
“消息”:“不应少于8个字符”,
“信息”:{
“限额”:8
}
}]
}
}

谢谢你的帮助

您可以按以下方式执行此操作:

export const CredentialsSchema = {
  type: 'object',
  required: ['email', 'password'],
  properties: {
    email: {
      type: 'string',
      format: 'email',
   },
   password: {
     type: 'string',
     minLength: 8,
     errors: {
        minLength: "Should be at least 8 characters long."
      }
   },
  },
};