开发者

How to handle multiple asynchronous errors on a single page?

开发者 https://www.devze.com 2022-12-13 19:57 出处:网络
This is not necessarily a Flex-specific question, but I\'ll use Flex in my example: Scenario: We have a fairly complex MVC Flex application that uses remoting and makes several asynchronous calls on

This is not necessarily a Flex-specific question, but I'll use Flex in my example:

Scenario: We have a fairly complex MVC Flex application that uses remoting and makes several asynchronous calls on a single page. Some of the calls are:

  • GetUserOrders
  • GetCurrentOrder
  • GetUserDetails

If there is a network or DB error, this will throw three separate error messages to the user and require three "OK" clicks. We are considering collecting all errors messages in a singleton array and displaying as a list in a common error message box.

What are be开发者_Go百科st practices around gracefully handle multiple asynchronous errors on a single page--specifically when we need to alert users that there was an error?


For network or DB errors, you might consider writing some code that catches those and just displays a status message rather than a series of alerts.

From the user's perspective, if the network or DB hit an error, they'll want to know when it's okay to start clicking again. If you expect these errors to only occur in rare situations, an alert seems okay. However, if it's possible the network or DB might be down for a while and therefore they'd get a lot of these messages, I'd put a status message somewhere and the status message says that the network or DB is down until it is able to complete a request successfully. I'd imagine you could continue allowing the user to click and maybe even pinging your server every few seconds until a request works. Once it does, you could clear the status message and everything would continue normally. Hopefully that makes sense.

JavaScript code snippet:

if (response.error) {
    if (response.error === 'some type') {
        showStatusMessage('Network/DB down');
        startPollingNetworkDBStatus();
    } else {
        // Additional error handling...
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消