Skip to content

Commit

Permalink
Make error messages useful when using SOAP 1.2 (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
nraynaud authored Jul 16, 2024
1 parent a00fa81 commit 683daee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,19 @@ export class WSDL {
if (root.Envelope) {
const body = root.Envelope.Body;
if (body && body.Fault) {
let code = body.Fault.faultcode && body.Fault.faultcode.$value;
let string = body.Fault.faultstring && body.Fault.faultstring.$value;
let detail = body.Fault.detail && body.Fault.detail.$value;

code = code || body.Fault.faultcode;
string = string || body.Fault.faultstring;
detail = detail || body.Fault.detail;
const fault = body.Fault;
let code = fault.faultcode && fault.faultcode.$value;
let string = fault.faultstring && fault.faultstring.$value;
let detail = fault.detail && fault.detail.$value;

code = code || fault.faultcode;
string = string || fault.faultstring;
detail = detail || fault.detail;
// SOAP 1.2
code = code || fault.Code && `${fault.Code.Value}: ${fault.Code.Subcode && fault.Code.Subcode.Value}`;
string = string || fault.Reason && fault.Reason.Text.$value;
string = string || fault.Reason && fault.Reason.Text;
detail = detail || fault.Detail;

const error: any = new Error(code + ': ' + string + (detail ? ': ' + JSON.stringify(detail) : ''));

Expand Down
8 changes: 4 additions & 4 deletions test/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test.service = {
Fault: {
Code: {
Value: "soap:Sender",
Subcode: { value: "rpc:BadArguments" }
Subcode: { Value: "rpc:BadArguments" }
},
Reason: { Text: "Processing Error" }
}
Expand All @@ -61,7 +61,7 @@ test.service = {
Fault: {
Code: {
Value: "soap:Sender",
Subcode: { value: "rpc:BadArguments" }
Subcode: { Value: "rpc:BadArguments" }
},
Reason: { Text: "Processing Error" },
statusCode: 500
Expand Down Expand Up @@ -458,7 +458,7 @@ describe('SOAP Server', function () {
client.GetLastTradePrice({ tickerSymbol: 'SOAP Fault v1.2' }, function (err, response, body) {
assert.ok(err);
var fault = err.root.Envelope.Body.Fault;
assert.equal(err.message, fault.faultcode + ': ' + fault.faultstring);
assert.equal(err.message, fault.Code.Value + ': ' + fault.Code.Subcode.Value + ': ' + fault.Reason.Text);
assert.equal(fault.Code.Value, "soap:Sender");
assert.equal(fault.Reason.Text, "Processing Error");
// Verify namespace on elements set according to fault spec 1.2
Expand Down Expand Up @@ -497,7 +497,7 @@ describe('SOAP Server', function () {
Fault: {
Code: {
Value: "soap:Sender",
Subcode: { value: "rpc:BadArguments" }
Subcode: { Value: "rpc:BadArguments" }
},
Reason: { Text: "Processing Error" }
}
Expand Down

0 comments on commit 683daee

Please sign in to comment.