I am using RC6 and I am trying to figure out how to catch HTTP errors - auth errors in particular - throughout the application.
There are a few posts that describe how to extend a class Httpwith a special class, but I'm not sure how to register a new class exactly as it seems that the syntax has changed with recent ngModule changes.
Here's the class (with all imported added added):
@Injectable()
export class InterceptedHttp extends Http {
constructor(backend: ConnectionBackend, defaultOptions: RequestOptions) {
super( backend, defaultOptions);
}
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
console.log('request...');
return super.request(url, options);
}
get(url: string, options?: RequestOptionsArgs): Observable<Response> {
console.log('get...');
return super.get(url,options);
}
}
I thought I could do the following in a section providers @ngModule:
imports: [ HttpModule, ... ],
providers: [
...
InterceptedHttp,
{provide: Http, useClass: InterceptedHttp },
ConnectionBackend
],
but it just causes me a lack of module errors:
ERROR in [default] C:/WebConnectionProjects/AlbumViewer/Web/src/app/app.module.ts:64:10
Argument of type '{ imports: (ModuleWithProviders | typeof BrowserModule)[]; declarations: (typeof AlbumList | type...' is not assignable to parameter of type 'NgModuleMetadataType'.
Types of property 'providers' are incompatible.
Type '(typeof ConnectionBackend | typeof Album | typeof Artist | typeof Track | typeof AppConfiguration...' is not assignable to type 'Provider[]'.
Type 'typeof ConnectionBackend | typeof Album | typeof Artist | typeof Track | typeof AppConfiguration ...' is not assignable to type 'Provider'.
Type 'typeof ConnectionBackend' is not assignable to type 'Provider'.
Type 'typeof ConnectionBackend' is not assignable to type 'FactoryProvider'.
Property 'provide' is missing in type 'typeof ConnectionBackend'.
deleting the added lines and everything works.
So how can I register a custom Http class?