Ionic's Angular Interceptor

Source: Internet
Author: User

Ionic as an application, certainly and the server has data exchange, decentralized processing API is too cumbersome, so the general use of interceptors to focus on processing.

Mainly by the following aspects of the application:

    1. Server Address Injection
    2. Error Handling
    3. Token injection
    4. Log Processing
    5. Skip to login page when no token
    6. ...

There are four ways of

Request:function (config) requesterror:function (config) response:function (response) Responseerror:function ( Response

Basically look at the method name to know its meaning. For specific usage and wording, please refer to: http://my.oschina.net/ilivebox/blog/290881?p=1

1, server injection, token injection:
Request:function (config) {   if (config.params)       config.params[' x-session-token '] = Cacheservice.token ();   Remote service, unified Add server address   var uri = Config.url;   if (Config.method = = "JSONP") {      Config.url = fgethost () + URI;      Config.uri = URI;   }   return config;}
2. Token timeout:
Response:function (response) {    if (Response.config.method = = "JSONP") {        if (!fiswhiteuri ( Response.config.uri) {            var login = response.data[' X-session-login '];            Force the user to log on            if (!login) {               $location. Path ('/user/login ');               Return $q. Reject (response);    }} return response;}
Description: 1, each time the incomingX-session-token parameters for back-end validation;

2. Back in the background

X-session-login:false
Indicates that token expires and needs to be logged back in.





Ionic's Angular Interceptor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.