javascriptnode.jsasync-awaitnode-soap

Node-Soap - throwing fault in async method


Created a soap api with the node-soap library but when i try to throw a fault using

throw {
    Fault: {
      Code: {
        Value: 'soap:Sender',
        Subcode: { value: 'rpc:BadArguments' }
      },
      Reason: { Text: 'Processing Error' }
    }
  };

as descibed in the library i get a

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)

this is what i am currently doing

                     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
                                }

thanks


Solution

  • Thanks, guys for your help but I got the issue

    if an async function is been used for the soap api been implemented with node-soap

    communication need to be done via callbacks

    i changed the throw to

                                                       callback({
                                                            Fault: {
                                                                error: {
                                                                    data: {
                                                                        error
                                                                    } 
                                                                }
                                                            }
    
                                                        });
    

    and it works perfectly

    i found it here node-soap doc