Skip to content

Instantly share code, notes, and snippets.

@joshwiens
Created November 8, 2016 22:23
Show Gist options
  • Save joshwiens/9352109b16a01574f8f0e698fab20d1d to your computer and use it in GitHub Desktop.
Save joshwiens/9352109b16a01574f8f0e698fab20d1d to your computer and use it in GitHub Desktop.
Basic HTTP Interception
import { Injectable } from '@angular/core';
import {
Http,
RequestOptions,
RequestOptionsArgs,
Response,
ConnectionBackend
} from '@angular/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class InterceptHttpService extends Http {
public constructor(_backend: ConnectionBackend, _defaultOptions: RequestOptions) {
super(_backend, _defaultOptions);
}
public get(url: string, options?: RequestOptionsArgs): Observable<Response> {
let response = super.get(url, options);
response.subscribe(null, error => {
// Execute the codez here :)
});
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment