Azure功能响应状态代码始终为200

时间:2018-08-12 07:29:19

标签: node.js azure azure-functions

我有一个应该根据一些内部逻辑返回错误状态500/400的函数。由于某些原因,无论我返回什么,Azure函数都会始终返回HTTP状态200。

这是一个样本

    if (err) { 
        console.error('some error :', err);                           
        context.res = { status: 400, body: err };
    } else {
        context.res = processRequest(context, req);
    }

    context.done();

返回状态200 OK

enter image description here

下面是我的函数绑定

{
  "bindings": [
{
  "authLevel": "function",
  "type": "httpTrigger",
  "direction": "in",
  "name": "req"
},
{
  "type": "http",
  "direction": "out",
  "name": "res"
}  
],  "disabled": false
}

1 个答案:

答案 0 :(得分:2)

啊!最终不得不将IsRaw属性设置为true

enter image description here

MS docs

            context.res = {
            headers: {
                'Content-Type': 'application/json'
            },
            status: 400,
            body: {
                err
            },
            isRaw: true,
            };
相关问题