Node-Soap - 在异步方法中抛出错误
Node-Soap - throwing fault in async method
使用 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
}
谢谢
在异步函数中抛出错误
parseString(res, async function (err, result)...
拒绝异步函数返回的承诺 - 对于它没有捕获处理程序。如果 parseString
同步调用其回调,您可以删除 async
声明,将调用保留为
parseString(res, function (err, result)...
但是,如果 parseString 是异步的,则需要对其进行承诺,以便将错误处理到周围的承诺链中。作为一个未经测试的例子:
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
谢谢大家的帮助,但我遇到了问题
如果 soap 使用异步函数 api 已用 node-soap
实现
需要通过回调进行通信
我把投掷改为
callback({
Fault: {
error: {
data: {
error
}
}
}
});
而且效果很好
我在这里找到的node-soap doc
使用 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
}
谢谢
在异步函数中抛出错误
parseString(res, async function (err, result)...
拒绝异步函数返回的承诺 - 对于它没有捕获处理程序。如果 parseString
同步调用其回调,您可以删除 async
声明,将调用保留为
parseString(res, function (err, result)...
但是,如果 parseString 是异步的,则需要对其进行承诺,以便将错误处理到周围的承诺链中。作为一个未经测试的例子:
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
谢谢大家的帮助,但我遇到了问题
如果 soap 使用异步函数 api 已用 node-soap
实现需要通过回调进行通信
我把投掷改为
callback({
Fault: {
error: {
data: {
error
}
}
}
});
而且效果很好
我在这里找到的node-soap doc