Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在使用Firebase REST API时处理注册用户错误_Javascript_Php_Node.js_Angular_Firebase Authentication - Fatal编程技术网

Javascript 如何在使用Firebase REST API时处理注册用户错误

Javascript 如何在使用Firebase REST API时处理注册用户错误,javascript,php,node.js,angular,firebase-authentication,Javascript,Php,Node.js,Angular,Firebase Authentication,我一直在尝试使用节点和Axios HTTP库注册一个使用Firebase Rest API的用户 我可以使用电子邮件和密码创建新用户 但是当数据库中已存在电子邮件或密码少于6个字符时,它不会显示正确的错误 它只返回请求失败,状态代码为400 这是我的密码 const config = { headers: { 'Content-Type': 'application/json', }, };

我一直在尝试使用节点和Axios HTTP库注册一个使用Firebase Rest API的用户

我可以使用
电子邮件
密码
创建新用户

但是当数据库中已存在
电子邮件或
密码少于6个字符时,它不会显示正确的错误

它只返回
请求失败,状态代码为400

这是我的密码

const config = 
    {
        headers:
        {
            'Content-Type': 'application/json',
        },
    }; 


    data = {
        'email': "test@test.com",
        'password': "password123",
        'returnSecureToken': true
    }

    try
    {
        let signup = await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY',data,config)

        res.json(signup.data);
    }
    catch(err)
    {
        res.json(err);
    }
我犯了一个错误

{
    "message": "Request failed with status code 400",
    "name": "Error",
    "stack": "Error: Request failed with status code 400\n    at createError (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/Users/user/NodeJS/FirebaseAuth/node_modules/axios/lib/adapters/http.js:244:11)\n    at IncomingMessage.emit (events.js:327:22)\n    at endReadableNT (_stream_readable.js:1224:12)\n    at processTicksAndRejections (internal/process/task_queues.js:84:21)",
    "config": {
        "url": "https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=API_KEY",
        "method": "post",
        "data": "{\"email\":\"test@test.com\",\"password\":\"password123\",\"returnSecureToken\":true}",
        "headers": {
            "Accept": "application/json, text/plain, */*",
            "Content-Type": "application/json",
            "User-Agent": "axios/0.21.0",
            "Content-Length": 75
        },
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1,
        "maxBodyLength": -1
    }
}
此处的预期错误为:电子邮件已存在。但它不会返回此错误

这里可能有什么问题


谢谢

默认情况下,firebase不会在错误正文中返回响应,但可以使用提取

console.log(err.response.data.error);
官方firebase文档中没有提到这一点