有没有办法在验证规则上设置特定的错误消息? [英] Is there a way to set specific error messages on validation rules?

查看:55
本文介绍了有没有办法在验证规则上设置特定的错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像"validate": "condition1 && condition2"这样的验证规则,并且我想根据不满足的第一个条件向用户显示错误消息.

Let's say that I have a validation rule like "validate": "condition1 && condition2" and I want to show the user an error message according to the first condition that is not met.

例如,如果未满足condition1,则用户将收到一条自定义消息,提示未满足条件1".

For example, if condition1 isn't met, the user would receive a custom message saying that "Condition1 is not met".

基本上,我想将错误代码(或消息)映射到每个条件,并将其发送给用户(而不是Firebase的经典权限被拒绝"消息).

Basically, I want to map an error code (or message) to each condition and that should be sent to the user (instead of the classic "Permission denied" message from Firebase).

推荐答案

没有办法做到这一点.您可以做的是使用Cloud Functions HTTP触发器作为用于写入数据的API.它可以检查您想要的条件,然后返回一个响应,指示客户端尝试写入的数据出了什么问题.我了解这远非理想,但它可能是您目前拥有的最佳选择.

There's not a way to do this. What you could do instead is use Cloud Functions HTTP triggers as an API for writing data. It could check the conditions you want, then return a response that indicates what's wrong with the data the client is trying to write. I understand this is far from ideal, but it might be the best option you have right now.

您还可以提交功能请求,其中包含有关内容的描述您正在尝试做.

You can also file a feature request with a description of what you're trying to do.

这篇关于有没有办法在验证规则上设置特定的错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆