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

Documentation about the ajax callback is confusing #315

Open
saraedum opened this issue Jun 11, 2019 · 7 comments
Open

Documentation about the ajax callback is confusing #315

saraedum opened this issue Jun 11, 2019 · 7 comments

Comments

@saraedum
Copy link

The README says that the ajax parameter takes a callback that should be called as follows:

  // 'callback' is a function that takes two parameters, 'data' and 'xhr'.
  //            'data' should be the key:value translation pairs for the
  //            requested language and namespace, or null in case of an error.
  //            'xhr' should be a status object, e.g. { status: 200 }

However, that's not what the included implementation does. When there is an error, it logs to the console and never calls the callback.

I tried to actually call with null on error and that did not work for me (at least not with the local storage backend in the next layer of a chained backend.) I could provide a minimal example if that helps here.

So, what is the right thing to do here? Just not call the callback as the default implementation does? Then the documentation should be updated.

@jamuhl
Copy link
Member

jamuhl commented Jun 11, 2019

more important is status as this is the trigger for sending back error with option for retry or fail permanently: https://github.com/i18next/i18next-xhr-backend/blob/master/src/index.js#L51

@saraedum
Copy link
Author

But the provided implementation does not actually report such errors as it does not seem to be calling the callback when an error happens. Or am I missing something?

@jamuhl
Copy link
Member

jamuhl commented Jun 11, 2019

like said...status is all that counts...read the code

@saraedum
Copy link
Author

When an exception happens, the callback is not called. It would probably be better to call it than to just log to the console. I'll try to create a PR for this and also improve the documentation a bit. It confused me at least. We can then discuss whether that's really an improvement :)

@jamuhl
Copy link
Member

jamuhl commented Jun 11, 2019

and what you like todo with the error? -> which only can be a network error (offline)...all other cases are handled with a retry or permanent fail which gets handled in the i18next events / callbacks

@saraedum
Copy link
Author

Reporting it to the caller with "no retry" seems most natural to me.

@jamuhl
Copy link
Member

jamuhl commented Jun 11, 2019

PR welcome

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