Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when XHR request fails and no fail handler is defined #147

Open
danports opened this issue Sep 23, 2022 · 1 comment
Open

Crash when XHR request fails and no fail handler is defined #147

danports opened this issue Sep 23, 2022 · 1 comment

Comments

@danports
Copy link

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:

this._settings?.fail(err);

That will check if _settings exists, but not whether fail is defined on that object. A more correct version (we can assume _settings exists here since it has a url we've already requested): this._settings.fail?.(err);

@4braincells
Copy link

4braincells commented Sep 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants