angular2-interceptors icon indicating copy to clipboard operation
angular2-interceptors copied to clipboard

How do I get to know about request data in InterceptedResponse?

Open abhishekdgeek opened this issue 7 years ago • 1 comments

I just have a application using this plugin and now have an application that needs me to work on InterceptedResponse with API request methods i.e. GET, PUT, POST, DELETE. Also I need to access request data.

Thanks.

abhishekdgeek avatar Nov 06 '17 09:11 abhishekdgeek

import {Interceptor, InterceptedRequest, InterceptedResponse} from 'ng2-interceptors';
import {Events} from "ionic-angular";
import {Injectable} from "@angular/core";

@Injectable()
export class ServerURLInterceptor implements Interceptor {

    constructor(public events: Events) {
    }

    public interceptBefore(request: InterceptedRequest): InterceptedRequest {
        return request;
    }

    public interceptAfter(response: InterceptedResponse): InterceptedResponse {
        try {
            let res = response.response['_body'];
            let body = JSON.parse(res);
            if (body.exception === 'NoOperatorException') {
                this.events.publish('need-login');
            }
        } finally {
        }

        return response;

    }

}

smallg avatar Dec 08 '17 02:12 smallg