leaguevine / leaguevine-ultistats

MIT License
18 stars 4 forks source link

Handle Event Submission Errors #49

Open mliu7 opened 12 years ago

mliu7 commented 12 years ago

When we are on the game tracking pages and events are being submitted in the background, the user currently has no way of knowing if the events were submitted successfully or not. Events generally get submitted successfully, but while playing around on my android phone, I ran into a a situation where the events were not being sent successfully so all of the work I was doing with entering events was not recorded.

One important thing to keep in mind when we handle this is that we need to check what the status of the error is before we handle it. If we are receiving 400 (Bad Request) or 401 (Unauthorized) errors, then we can be confident that our app is just not working right. If we receive 500 (Internal server error) errors, then we can ignore them because those are Leaguevine's fault.

If we detect that the app is in a bad state where no events are being sent correctly, we should give the user an error message, prompt the user to log out (which clears the localstorage authentication parameters), and redirect the user to an authentication page so we can start fresh with new credentials. Successfully filling out this form should redirect back to the page the user was originally on.

cboulay commented 12 years ago

The WebSQL-Ajax synchronization plugin is almost done. I just have to figure out how to make sure the queue is processed 1 item at a time, i.e., the next item is not processed until the previous item's success callback.

The way the plugin works, the event will be added to the local db immediately and the response data (only) will be returned to Backbone. This will not return an HTTP response. However, the event will simultaneously be added to the queue along with its callbacks. When the queue is processed the AJAX request will be created with the aforementioned data and callbacks. My concern is how we want to handle the error when the error comes from processing an item that was entered into the queue several minutes ago. We can alert the user that there is a problem, but it might not be relevant to the current game/screen/action.

Generally Backbone's built-in callbacks simply update the model and fire the appropriate event (like "sync" or "change") or trigger "error", so they will have no effect if there is no view monitoring those models' events.

I'm thinking we'll need to handle 401's or 500's by leaving the item in the queue (and authenticating in the case of 401). This can be done by the plugin because I think it is a safe assumption that this will be the desired outcome in all cases. I don't know how to handle a 400 other than alerting the user so they can report it to us. I think it's too much to create an interface to allow editing individual events that may have happened several minutes ago. Instead we should try to make sure these errors never happen.

tldr; The plugin will handle 401 and 500 errors but you can write some code for now that I will use once the plugin is ready.

mliu7 commented 12 years ago

Cool, thanks for that info. It sounds like a really good solution.

I haven't started on this, and if I get to it before you I'll assign myself to it before I work on it. I'm trying to be more consistent about assigning myself to issues before I begin working on them.

mliu7 commented 11 years ago

Bump.

Does the plugin now handle errors? And if so, can we start showing these errors to the user?

I occasionally run into an issue where the game tracking screen isn't sending events to leaguevine correctly. This doesn't happen often and I can never seem to reproduce these errors when I try, but if I'm having issues I'm guessing others are occasionally as well so we should alert them that there are errors and they should re-login or something so they aren't entering lots of data for nothing.

cboulay commented 11 years ago

I seemed to have found a plugin that does everything I was attempting to do and more, though it doesn't use WebSQL it uses OfflineStorage. This may or may not be a problem depending on how the data are indexed with this plugin. https://github.com/Ask11/backbone.offline

I'll branch ultistats and give this plugin a shot. I don't have any time these days as I'm gearing up for a conference in New Orleans. But I am using django and javascript at work so hopefully my web skills will develop.

mliu7 commented 11 years ago

Very cool. I look forward to hearing how it works.