当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - How to display HTTP error messages on ionic app?

问题描述:

Is there a standard way of showing error messages on ionic mobile app.

From the documentation I couldn't find any information associated with showing error messages.

Doc referred: http://ionicframework.com/docs/components/

网友答案:

Consider you want to send all HTTP errors to Modal you can override exceptions by using $provide decorator "$exceptionHandler" :

$provide.decorator("$exceptionHandler", function($delegate, $injector)   {
        return function(exception, cause) {
           /* here you can do what u want  */
  });

To send to native code or even to Crashlytics (reporting server) use Cordova bridge:

app.config(function($provide) {

    $provide.decorator("$exceptionHandler", function($delegate, $injector) {
        return function(exception, cause) {

            if (false) { //(appState !== "...") { // We want to only send the error in this case

                $delegate(exception, cause);

            } else {
                //appState == null;

                var MyCordovaService = $injector.get("MyCordovaService");

                console.debug({reason: exception, message: exception.message, stack: exception.stack});

                var data = {
                    message: "Exception: " + exception.message,
                    stack: exception.stack || "none"
                };

                MyCordovaService.reportClientError(data).then(function(data) {
                    console.debug('reportClientError success', data);
                }, function(error) {
                    console.debug('reportClientError fail!', error);
                });
                //}



                // Call The original Angular Exception Handler
                $delegate(exception, cause);
            }
        };
    });

});

Demo in Codepan


Hope it will help,

分享给朋友:
您可能感兴趣的文章:
随机阅读: