1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

replace deprecated toPromise with last value

This commit is contained in:
Patrik J. Braun 2023-10-08 00:59:00 +02:00
parent f3d862c96a
commit 07c827ec1b

View File

@ -7,6 +7,7 @@ import {Config} from '../../../../common/config/public/Config';
import {Utils} from '../../../../common/Utils'; import {Utils} from '../../../../common/Utils';
import {CustomHeaders} from '../../../../common/CustomHeaders'; import {CustomHeaders} from '../../../../common/CustomHeaders';
import {VersionService} from '../version.service'; import {VersionService} from '../version.service';
import { lastValueFrom } from 'rxjs';
@Injectable() @Injectable()
export class NetworkService { export class NetworkService {
@ -50,9 +51,8 @@ export class NetworkService {
return this.handleError(error); return this.handleError(error);
}; };
return this.http return lastValueFrom(this.http
.get(this.apiBaseUrl + url, {responseType: 'text'}) .get(this.apiBaseUrl + url, {responseType: 'text'}))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
} }
@ -70,9 +70,8 @@ export class NetworkService {
return this.handleError(error); return this.handleError(error);
}; };
return this.http return lastValueFrom(this.http
.get(this.apiBaseUrl + url, {responseType: 'text'}) .get(this.apiBaseUrl + url, {responseType: 'text'}))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
} }
@ -130,29 +129,25 @@ export class NetworkService {
switch (method) { switch (method) {
case 'get': case 'get':
return this.http return lastValueFrom(this.http
.get<Message<T>>(this.apiBaseUrl + url, {observe: 'response'}) .get<Message<T>>(this.apiBaseUrl + url, {observe: 'response'}))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
case 'delete': case 'delete':
return this.http return lastValueFrom(this.http
.delete<Message<T>>(this.apiBaseUrl + url, {observe: 'response'}) .delete<Message<T>>(this.apiBaseUrl + url, {observe: 'response'}))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
case 'post': case 'post':
return this.http return lastValueFrom(this.http
.post<Message<T>>(this.apiBaseUrl + url, body, { .post<Message<T>>(this.apiBaseUrl + url, body, {
observe: 'response', observe: 'response',
}) }))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
case 'put': case 'put':
return this.http return lastValueFrom(this.http
.put<Message<T>>(this.apiBaseUrl + url, body, {observe: 'response'}) .put<Message<T>>(this.apiBaseUrl + url, body, {observe: 'response'}))
.toPromise()
.then(process) .then(process)
.catch(err); .catch(err);
default: default: