【问题标题】:How to send error message from node express to retrofit on android如何从 node express 发送错误消息以在 android 上进行改造
【发布时间】:2016-06-07 20:50:06
【问题描述】:

我有一个节点服务器,在我的 android 设备上我正在使用改造来与我的 API 对话。

如果我从服务器 res.json(User)res.send("message") 进行常规/成功响应,我会正确获取 android 上的响应正文。

public void onResponse(Call<User> call, Response<User> response) {
    //response contains a body or message
}

但是,如果我想发送错误,请使用

res.status(500).json({"msg":"user not found");

res.status(500).send("user not found")

在我的改造回调中,我收到一个带有正确状态代码的成功回调,在本例中为 500,但我尝试发送的错误消息没有传递给我。

似乎由于http响应状态是错误状态,改造只是忽略了响应正文/内容。

如何发送错误状态 500,同时发送数据以进行改造?

【问题讨论】:

    标签: android node.js retrofit


    【解决方案1】:

    我总是使用这种方法:

    res.send({status:200, "msg":"user not found"});
    

    【讨论】:

    • 我想我可以做到,但问题是我们的 iOS 应用程序依赖于当前的方法,我们不想改变它。
    猜你喜欢
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 2016-06-22
    • 1970-01-01
    • 2019-06-25
    • 2016-06-12
    • 1970-01-01
    相关资源
    最近更新 更多