为了账号安全,请及时绑定邮箱和手机立即绑定

Node-Soap-在异步方法中引发错误

Node-Soap-在异步方法中引发错误

慕少森 2021-04-06 16:13:35
使用node-soap库创建了一个SOAP API,但是当我尝试使用以下方法抛出错误时throw {    Fault: {      Code: {        Value: 'soap:Sender',        Subcode: { value: 'rpc:BadArguments' }      },      Reason: { Text: 'Processing Error' }    }  };根据图书馆的描述,我得到了一个UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)这是我目前正在做的                     ssm.decrypt(args.request, password, base_key)                        .then(function (res) {                            console.log(res)                            parseString(res, async function (err, result) {                                if (err) {                               //the throws causes the error                                    throw {                                        Fault: {                                            error: {                                                data: {                                                    error                                                } //Error object from catch                                            }                                        }                                    };                                } else {                                 //some code                                }谢谢
查看完整描述

2 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

谢谢大家的帮助,但我遇到了问题


如果为soap api使用了异步功能,是否已通过node-soap实现


通讯需要通过回调来完成


我将投掷更改为


                                                   callback({

                                                        Fault: {

                                                            error: {

                                                                data: {

                                                                    error

                                                                } 

                                                            }

                                                        }


                                                    });

而且效果很好


查看完整回答
反对 回复 2021-04-22
?
喵喵时光机

TA贡献1846条经验 获得超7个赞

在异步函数内引发错误


parseString(res, async function (err, result)...

拒绝异步函数返回的promise-没有捕获处理程序。如果parseString同步调用其回调,则只需删除async声明即可,将调用保留为


 parseString(res, function (err, result)...

但是,如果parseString是异步的,则需要对其进行承诺,以便可以将错误处理到周围的promise链中。作为一个未经测试的示例:


function doParseString( res) {

    return new Promise( function( resolve, reject) {

        parseSting( res, function( err, result) {

             err ? reject( err) : resolve( result);

        });  

    });

}

可以按照以下方式使用


ssm.decrypt(args.request, password, base_key)

.then( doParseString)

.then( function  (result) {

     // some code

 })

.catch( console.log);   // do something with the error


查看完整回答
反对 回复 2021-04-22
  • 2 回答
  • 0 关注
  • 200 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信