-
Notifications
You must be signed in to change notification settings - Fork 3
SOAPFault
do- edited this page Dec 10, 2022
·
8 revisions
A lightweight object to represent SOAP faults in a version agnostic manner, to be stringified with SOAP11 or SOAP12.
const {SOAP11, SOAP12, SOAPFault} = require ('xml-toolkit')
const header = '<SecureToken/>'
const soap = SOAP11 // or maybe SOAP12
function SomeSOAPServiceImpl (rq) {
try {
const rp = handleRequest (rq)
return soap.message (rp, header)
}
catch (xxx) {
// const fault = new SOAPFault (xxx) // too easy
const fault = new SOAPFault (xxx.message, {
actor: 'Client',
detail: '<id>1</id>',
})
return soap.message (fault, header)
}
}
In simplest form, SOAPFault can be constructed with just a faultString
value:
const fault = new SOAPFault ('Internal Server Error')
This is exactly the same as passing an object with a property named message
:
const fault = new SOAPFault ({message: 'Internal Server Error'})
which may happen to be a standard Error instance:
catch (x) {
const fault = new SOAPFault (x)
}
That object can have some additional properties:
catch (x) {
x.actor = 'Client'
const fault1 = new SOAPFault (x)
}
const fault2 = new SOAPFault ({
message: "It's totally your fault",
x.actor = 'Client'
})
Finally, a two-argument form is available, where the message text is mentioned first, followed by a bag of other options:
const fault = new SOAPFault ("It's totally your fault", {
x.actor = 'Client'
})
name | SOAP 1.1 | SOAP 1.2 | Notes |
---|---|---|---|
message |
faultstring |
Reason / Text |
mandatory |
code |
faultcode |
Code / Value |
|
actor |
faultactor |
Role |
Server by default; attached to SOAP namespace |
role |
faultactor |
Role |
alias for actor
|
detail |
detail |
Detail |
injected as is, so must be a well formed XML fragment |