如何修改Loopback 4中的错误消息? [英] How to modify error messages in Loopback 4?
本文介绍了如何修改Loopback 4中的错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是Loopback为唯一商品生成的示例错误消息:
Here's a sample error message generated by Loopback for unique item:
{
"error": {
"statusCode": "422",
"name": "Error",
"message": "ER_DUP_ENTRY: Duplicate entry 's@a.com' for key 'email'",
"code": "ER_DUP_ENTRY"
}
}
但是,我要将其修改为:
However, I want to modify it as:
{
"errors": {
"email": [
"The field email should be unique"
]
}
}
文档确实对我没有帮助.有人可以帮我吗?
Documentation really didn't help me. Can anybody help me on this please?
推荐答案
您可以使用@loopback/rest
中的HttpErrors
对象返回自定义错误.请点击此处以获取更多信息.>
You can return custom error using HttpErrors
object from @loopback/rest
. Please click here for more.
throw new HttpErrors.UnprocessableEntity('limit is not a natural number');
这篇关于如何修改Loopback 4中的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文