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

Interceptor for Failed requests? #19

Closed
djds4rce opened this issue Sep 25, 2015 · 1 comment
Closed

Interceptor for Failed requests? #19

djds4rce opened this issue Sep 25, 2015 · 1 comment

Comments

@djds4rce
Copy link

Shouldn't there be a global configuration to handle failed request instead of handling it in the error of every request?
Eg: I was handle session failures and instead of handling it in every request a global interceptor like Angular JS would be great.
https://djds4rce.wordpress.com/2013/08/13/understanding-angular-http-interceptors/

@stanleyw
Copy link
Contributor

Hi Dayanand,

We considered the global error handler option when we implemented revocable sessions earlier, and decided against it. We believe it makes your code more confusing to read/debug by a collaborator because the handler is not explicitly stated in the request code. In addition, when the session token becomes invalid, the best error handling logic could be dependent on where the user is in the app; you may want to perform additional operations before forcing the user to log in again (e.g. perhaps save the currently unfinished document to local storage so it can be recovered after the user logs in again).

If you want to use the same error handling logic for all calls, we recommend the following pattern:

let globalErrorHandler = (error) => {
  switch (error.code) {
    case Parse.Error.INVALID_SESSION_TOKEN:
      // Do whatever makes sense for invalid session
    case Parse.Error.SOME_OTHER_ERROR_CODE:
      // Handle another type of error
    ...
  }
}

// Then refer to this error handler from all network request calls in your app
obj.save().then(function(obj) { ... }, globalErrorHandler);

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

3 participants