Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习 node 和 express,我注意到一些教程喜欢发送如下所示的响应:
{status: “Success”, message: “custom message”, response: {actual response object}}
我的问题是,添加额外的状态和消息字段有什么意义?为什么不直接返回响应对象呢?
原因很简单,方便。它向客户端发送一条关于status请求的明确消息以及基于该请求显示什么消息status。它只是一种很好的编程实践,有助于根据如何处理客户端请求中的错误来构建代码库。
status