总是在Node.js中获得http状态代码200

时间:2019-06-14 08:32:08

标签: node.js http

我正在使用Node.js作为React App和Dynamics Nav之间的代理服务器。我在OData和SOAP Web服务中都进行了获取,发布,放置和删除请求。当Dynamics Nav Server响应错误时,我需要在React App中显示它。问题是,即使遇到错误,我也总是在Node.js中获得http 200状态代码。这是Node.js和Postman中的放置请求的示例响应:

邮递员

enter image description here

Node.js

enter image description here

这是server.js文件:

const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();

const server = app.listen(5000, function() {
    console.log(new Date().toISOString() + ": server started on port 5000");
});

server.on('connection', (socket) => {
    console.log('New connection...');
});


app.use(bodyParser.urlencoded({ extended: false }));

// parse application/json
app.use(bodyParser.json());
app.use(cors());

//app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', function (req, res) {
    res.send('Express for courier is working on IISNode!');
});

app.use(require('./routes/routesLogin'));
app.use(require('./routes/routesCustomers'));
app.use(require('./routes/routesContacts'));
app.use(require('./routes/routesPostCodes'));
app.use(require('./routes/routesCountriesRegions'));
app.use(require('./routes/routesDepots'));
app.use(require('./routes/routesPUOrder'));

这是放置请求的功能:

    ModifyPUOrder: function (req, res) {
        console.log('MODIFY');
        const PUOrderNo = req.body.puOrderNo;
        const updatedValue = req.body.updatedValue;
        console.log('MODIFY PU', PUOrderNo);
        console.log('UPDATEDVALUE', updatedValue)
        const url = `${base}/PUOrderCard('${PUOrderNo}')`;

        request =   `{ ${updatedValue} }`;

        put(username, password, url, request).then(response => {
            console.log(response);
            res.send(response);
        })
    },

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

Express中响应的默认状态代码为1,您可以在致电200之前更改此代码

send