错误:自定义代码回调中的问题:RangeError:无效的状态代码:0

时间:2019-05-03 02:25:10

标签: angular ionic-framework http-headers

我正在创建从API检索/写入数据并为Android应用程序使用http native的应用程序。获取方法现在可以了。但是,当我使用邮寄和修补程序保存数据时,该方法尚无法使用。

能否请您指导我如何使用POST保存数据?这是我的代码,如下所示:

在service.ts中,

 updateProfile(userProfile) {
    console.log("UpdatePro_"+JSON.stringify(userProfile));
    return this.http.patch(this.mcs.mobileBackend.getCustomCodeUrl(mcsConfig.environment + '_api_care/my/profile'), userProfile, this.getMcsHeadersString());
  }

getMcsHeadersString() {
    var cheaders = {};
    for (let key in this.mcs.mobileBackend.getHttpHeaders()) {
      cheaders[key]= this.mcs.mobileBackend.getHttpHeaders()[key];
    }
    //console.log("STring_HeaderKey_"+cheaders['_keys']+"HeaderValue_"+cheaders['_values']);
    delete cheaders['_keys'];
    delete cheaders['_values'];
    return cheaders;
  } 

在profileedit.ts

save() {

    this.mcsService.updateProfile(this.userProfile).then((res) => {

      console.log("testUp"+this.userProfile);
      this.router.navigate(['menu/profile']);
    }, (err) => {
      console.log("Invalid_"+err.error);
      this.presentAlert(err.error);
    }
    );
  }

错误消息显示如下:

{"message":"Custom Code Problem in callback: RangeError: Invalid status code: 0"}

Custom Code Problem in callback: 
request:
 patch  /profile
caused unhandled error:
 RangeError: Invalid status code: 0
    at ServerResponse.writeHead (_http_server.js:192:11)
    at ServerResponse.res.writeHead (/u01/app/mobile_ccc/mcs-node-router/mcs-node-server.js:765:35)
    at ServerResponse._implicitHeader (_http_server.js:157:8)
    at ServerResponse.OutgoingMessage.end (_http_outgoing.js:571:10)
    at ServerResponse.send (/u01/app/mobile_ccc/node-configurations/6.10/node_modules/express/lib/response.js:205:10)
    at getMyProfileRow.then.catch (/u01/app/mobile_ccc/custom_code_modules/01fead32-6294-4f8e-8dcb-fa405af7d75a_6/rest_api/custom/my/router_dbtable.js:545:36)

1 个答案:

答案 0 :(得分:0)

答案是我需要解析JSON obj,例如this.userProfile.user_name = JSON.parse(mcsService.userProfile).user_name;