discourse/discourse — pull request #2252 by riking (2014-04-10 23:20:52+00:00)
Title: Generic error handling framework for AJAX calls

This PR is the start of something that I've rewritten several times, because the diffs just get too big, so I keep giving up.

I'm submitting this part by itself so that I know I can have it to work off of when I start doing the refactoring. (Note the 'framework' in the title? :stuck_out_tongue: )

Also, the team can start to use it in new code, and maybe someone will get it to detect timeouts.

Commit message:

>This adds two variables to the Discourse global, genericErrorCaught and genericErrorRethrow.
>
>genericErrorRethrow simply calls genericErrorCaught and then chains the promise failure. This is required in cases where you have multiple .then() calls.
>
>genericErrorCaught creates a bootbox popup with either the error message(s) returned by the server or a generic message.
>
>A good 'next goal' would be to have genericErrorCaught also recognize network timeouts and display a different message.
>
>Additionally, 'json' is filled in on all requests to the server, not just GET requests. We already always set the dataType when we want HTML.