angular2-interceptors
angular2-interceptors copied to clipboard
How do I get to know about request data in InterceptedResponse?
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.
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;
}
}