Skip to content

Commit 27e853a

Browse files
mrkpksvmasek
authored andcommitted
fix(api-client): throwError is used instead of deprecated Observable.throw (#51)
1 parent 1704ad3 commit 27e853a

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

templates/ngx-service.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
5-
import { Observable } from 'rxjs';
5+
import { Observable, throwError } from 'rxjs';
66
import { DefaultHttpOptions, HttpOptions } from './';
77

88
{{#definitions.length}}
@@ -27,7 +27,7 @@ export class APIClient {
2727
2828
private readonly domain: string = `{{&domain}}`;
2929

30-
constructor(private http: HttpClient,
30+
constructor(private readonly http: HttpClient,
3131
@Optional() @Inject(USE_DOMAIN) domain: string,
3232
@Optional() @Inject(USE_HTTP_OPTIONS) options: DefaultHttpOptions) {
3333
@@ -105,7 +105,7 @@ export class APIClient {
105105
return this.http.put<T>(`${this.domain}${path}`, body, options);
106106
default:
107107
console.error(`Unsupported request: ${method}`);
108-
return Observable.throw(`Unsupported request: ${method}`);
108+
return throwError(`Unsupported request: ${method}`);
109109
}
110110
}
111111
}

tests/custom/api/api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
5-
import { Observable } from 'rxjs';
5+
import { Observable, throwError } from 'rxjs';
66
import { DefaultHttpOptions, HttpOptions } from './';
77

88
import * as models from './models';
@@ -25,7 +25,7 @@ export class APIClient {
2525

2626
private readonly domain: string = `//${window.location.hostname}${window.location.port ? ':'+window.location.port : ''}`;
2727

28-
constructor(private http: HttpClient,
28+
constructor(private readonly http: HttpClient,
2929
@Optional() @Inject(USE_DOMAIN) domain: string,
3030
@Optional() @Inject(USE_HTTP_OPTIONS) options: DefaultHttpOptions) {
3131

@@ -97,7 +97,7 @@ export class APIClient {
9797
return this.http.put<T>(`${this.domain}${path}`, body, options);
9898
default:
9999
console.error(`Unsupported request: ${method}`);
100-
return Observable.throw(`Unsupported request: ${method}`);
100+
return throwError(`Unsupported request: ${method}`);
101101
}
102102
}
103103
}

tests/esquare/api/api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
5-
import { Observable } from 'rxjs';
5+
import { Observable, throwError } from 'rxjs';
66
import { DefaultHttpOptions, HttpOptions } from './';
77

88
import * as models from './models';
@@ -25,7 +25,7 @@ export class APIClient {
2525

2626
private readonly domain: string = `https://virtserver.swaggerhub.com/Esquare/EsquareAPI/1.0.0`;
2727

28-
constructor(private http: HttpClient,
28+
constructor(private readonly http: HttpClient,
2929
@Optional() @Inject(USE_DOMAIN) domain: string,
3030
@Optional() @Inject(USE_HTTP_OPTIONS) options: DefaultHttpOptions) {
3131

@@ -865,7 +865,7 @@ export class APIClient {
865865
return this.http.put<T>(`${this.domain}${path}`, body, options);
866866
default:
867867
console.error(`Unsupported request: ${method}`);
868-
return Observable.throw(`Unsupported request: ${method}`);
868+
return throwError(`Unsupported request: ${method}`);
869869
}
870870
}
871871
}

tests/gcloud-firestore/api/api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
5-
import { Observable } from 'rxjs';
5+
import { Observable, throwError } from 'rxjs';
66
import { DefaultHttpOptions, HttpOptions } from './';
77

88
import * as models from './models';
@@ -25,7 +25,7 @@ export class APIClient {
2525

2626
private readonly domain: string = `https://firestore.googleapis.com/v1beta1`;
2727

28-
constructor(private http: HttpClient,
28+
constructor(private readonly http: HttpClient,
2929
@Optional() @Inject(USE_DOMAIN) domain: string,
3030
@Optional() @Inject(USE_HTTP_OPTIONS) options: DefaultHttpOptions) {
3131

@@ -346,7 +346,7 @@ export class APIClient {
346346
return this.http.put<T>(`${this.domain}${path}`, body, options);
347347
default:
348348
console.error(`Unsupported request: ${method}`);
349-
return Observable.throw(`Unsupported request: ${method}`);
349+
return throwError(`Unsupported request: ${method}`);
350350
}
351351
}
352352
}

tests/github/api/api-client.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
5-
import { Observable } from 'rxjs';
5+
import { Observable, throwError } from 'rxjs';
66
import { DefaultHttpOptions, HttpOptions } from './';
77

88
import * as models from './models';
@@ -25,7 +25,7 @@ export class APIClient {
2525

2626
private readonly domain: string = `https://api.github.com`;
2727

28-
constructor(private http: HttpClient,
28+
constructor(private readonly http: HttpClient,
2929
@Optional() @Inject(USE_DOMAIN) domain: string,
3030
@Optional() @Inject(USE_HTTP_OPTIONS) options: DefaultHttpOptions) {
3131

@@ -9434,7 +9434,7 @@ export class APIClient {
94349434
return this.http.put<T>(`${this.domain}${path}`, body, options);
94359435
default:
94369436
console.error(`Unsupported request: ${method}`);
9437-
return Observable.throw(`Unsupported request: ${method}`);
9437+
return throwError(`Unsupported request: ${method}`);
94389438
}
94399439
}
94409440
}

0 commit comments

Comments
 (0)