Open danports opened 1 year ago
this._settings?.fail(err);
is the same as
this._settings && this._settings.fail(err);
but not
this._settings.fail && this._settings.fail(err);
in my case, _settings is defined, not fail, so this will throw an exception. As settings is also optional, it should be
this.jqXHR.fail((err) => {
console.error(err);
this._settings && this._settings.fail && this._settings.fail(err);
// or this._settings?.fail?.(err);
});
(as already said by danports) or some more elegant version of this :-p thus preventing the exception to be thrown.
If an XHR request fails without a defined
fail
handler, the following error is thrown:fail is not a function
It looks like the XHR failure code doesn't check whether
fail
is actually defined in the settings object: https://github.com/xcash/bootstrap-autocomplete/blob/d9701bf90772f9b9b37246e8df604f15a6969884/src/resolvers.ts#L79That will check if
_settings
exists, but not whetherfail
is defined on that object. A more correct version (we can assume_settings
exists here since it has aurl
we've already requested):this._settings.fail?.(err);