Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
Node.js firebase Http函数错误_Node.js_Firebase_Express_Axios - Fatal编程技术网

Node.js firebase Http函数错误

Node.js firebase Http函数错误,node.js,firebase,express,axios,Node.js,Firebase,Express,Axios,我已经编写了一个Firebase Http函数。 成功时,返回状态200和一些数据。 当出现错误时,我希望客户端(使用axios.post)使用标准错误处理程序,这意味着显示error.message属性 如果我将错误代码与数据一起发送回来-是的,我可以在error.response.data中访问该数据/消息等,但这不是我可以用于所有错误的模式-可能会发生一些没有给出响应或数据属性的错误 因此,如果我只想在客户端访问error.message,我需要能够设置该消息,但此时如果我使用例如:- r

我已经编写了一个Firebase Http函数。 成功时,返回状态200和一些数据。 当出现错误时,我希望客户端(使用axios.post)使用标准错误处理程序,这意味着显示
error.message
属性

如果我将错误代码与数据一起发送回来-是的,我可以在
error.response.data
中访问该数据/消息等,但这不是我可以用于所有错误的模式-可能会发生一些没有给出响应或数据属性的错误

因此,如果我只想在客户端访问error.message,我需要能够设置该消息,但此时如果我使用例如:-

res.status(520).send('My custom error message')
我得到:

请求失败,状态为520

在error.message中,我必须转到error.response.data以获取我要显示的实际消息

我如何才能做到这一点,使我只使用
error.message
而不管它是什么?我试过使用

res.status(x).send({error:customerror})
也试过

res.statusText = customerror
正如您在Axios上看到的,您必须使用error.response从自定义消息中获取信息。您将无法在Axios上设置error.message的值。
如果您真的需要使用error.message,那么您必须在客户机上创建一个自定义函数来更改它。

实际上,这是一段代码,首先检查error.response是否正确,然后再检查其他可能的错误(error.request),这就是我的问题试图避免的。我希望error.message至少在所有情况下都能保存该消息,并且我可以从服务器设置该消息。