diff --git a/src/wsdl/index.ts b/src/wsdl/index.ts index 7c6a6680..fc41ae39 100644 --- a/src/wsdl/index.ts +++ b/src/wsdl/index.ts @@ -1209,15 +1209,19 @@ export class WSDL { includePath = url.resolve(this.uri || '', include.location); } - if (this.options.wsdl_options !== undefined && typeof this.options.wsdl_options.overrideImportLocation === 'function') { - includePath = this.options.wsdl_options.overrideImportLocation(includePath); - } - const options = Object.assign({}, this.options); // follow supplied ignoredNamespaces option options.ignoredNamespaces = this._originalIgnoredNamespaces || this.options.ignoredNamespaces; options.WSDL_CACHE = this.WSDL_CACHE; + if (this.options.wsdl_options !== undefined && typeof this.options.wsdl_options.overrideImportLocation === 'function') { + try { + includePath = this.options.wsdl_options.overrideImportLocation(includePath, this.uri, include.location, options); + } catch (e) { + return callback(e); + } + } + open_wsdl_recursive(includePath, options, (err, wsdl) => { if (err) { return callback(err); diff --git a/test/wsdl-test.js b/test/wsdl-test.js index 3b21bbe3..77fb0879 100644 --- a/test/wsdl-test.js +++ b/test/wsdl-test.js @@ -75,6 +75,28 @@ describe('WSDL Parser (strict)', () => { }); }); + it('should catch error on overrideImportLocation option', (done) => { + const options = { + strict: true, + wsdl_options: { + overrideImportLocation: (location, parent, include, options) => { + assert.equal(location, __dirname+'/wsdl/wsdlImport/sub.wsdl'); + assert.equal(parent, __dirname+'/wsdl/wsdlImport/main.wsdl'); + assert.equal(include, 'sub.wsdl') + assert.notEqual(options, null); + throw new Error(`user error`); + } + }, + disableCache: true, + }; + + soap.createClient(__dirname+'/wsdl/wsdlImport/main.wsdl', options, function(err, client){ + assert.notEqual(err, null); + assert.equal(err.message, 'user error'); + done(); + }); + }); + it('should get the parent namespace when parent namespace is empty string', (done) => { soap.createClient(__dirname+'/wsdl/marketo.wsdl', {strict: true}, function(err, client){ assert.ifError(err);