diff --git a/application/src/main/java/org/thingsboard/server/controller/RpcV2Controller.java b/application/src/main/java/org/thingsboard/server/controller/RpcV2Controller.java index b7c617259f..ae9081c39a 100644 --- a/application/src/main/java/org/thingsboard/server/controller/RpcV2Controller.java +++ b/application/src/main/java/org/thingsboard/server/controller/RpcV2Controller.java @@ -69,27 +69,11 @@ public class RpcV2Controller extends AbstractRpcController { @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.GET) @ResponseBody - public ResponseEntity getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException { + public Rpc getPersistedRpc(@PathVariable("rpcId") String strRpc) throws ThingsboardException { checkParameter("RpcId", strRpc); try { RpcId rpcId = new RpcId(UUID.fromString(strRpc)); - Rpc rpc = checkRpcId(rpcId, Operation.READ); - HttpStatus status; - switch (rpc.getStatus()) { - case FAILED: - status = HttpStatus.BAD_GATEWAY; - break; - case TIMEOUT: - status = HttpStatus.GATEWAY_TIMEOUT; - break; - case QUEUED: - case DELIVERED: - status = HttpStatus.ACCEPTED; - break; - default: - status = HttpStatus.OK; - } - return new ResponseEntity<>(rpc, status); + return checkRpcId(rpcId, Operation.READ); } catch (Exception e) { throw handleException(e); } diff --git a/ui-ngx/src/app/core/api/widget-subscription.ts b/ui-ngx/src/app/core/api/widget-subscription.ts index d888f759a8..e34fccf9c8 100644 --- a/ui-ngx/src/app/core/api/widget-subscription.ts +++ b/ui-ngx/src/app/core/api/widget-subscription.ts @@ -35,7 +35,7 @@ import { LegendKeyData, widgetType } from '@app/shared/models/widget.models'; -import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { HttpErrorResponse } from '@angular/common/http'; import { calculateIntervalStartEndTime, calculateTsOffset, @@ -69,7 +69,7 @@ import { } from '@shared/models/query/query.models'; import { filter, map, switchMap, takeUntil } from 'rxjs/operators'; import { AlarmDataListener } from '@core/api/alarm-data.service'; -import { PersistentRpc } from '@shared/models/rpc.models'; +import { RpcStatus } from '@shared/models/rpc.models'; const moment = moment_; @@ -710,8 +710,17 @@ export class WidgetSubscription implements IWidgetSubscription { if (persistent && persistentPollingInterval > 0) { return timer(persistentPollingInterval / 2, persistentPollingInterval).pipe( switchMap(() => this.ctx.deviceService.getPersistedRpc(response.rpcId, true)), - filter((persistentResponse: HttpResponse) => persistentResponse.status !== 202), - map(persistentResponse => persistentResponse.body.response), + filter(persistentRespons => + persistentRespons.status !== RpcStatus.DELIVERED && persistentRespons.status !== RpcStatus.QUEUED), + switchMap(persistentResponse => { + if (persistentResponse.status === RpcStatus.TIMEOUT) { + return throwError({status: 504}); + } else if (persistentResponse.status === RpcStatus.FAILED) { + return throwError({status: 502, statusText: persistentResponse.response.error}); + } else { + return of(persistentResponse.response); + } + }), takeUntil(rpcSubject) ); } diff --git a/ui-ngx/src/app/core/http/device.service.ts b/ui-ngx/src/app/core/http/device.service.ts index 77ee67f8c8..c881e038e9 100644 --- a/ui-ngx/src/app/core/http/device.service.ts +++ b/ui-ngx/src/app/core/http/device.service.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; import { Observable, ReplaySubject } from 'rxjs'; -import { HttpClient, HttpResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { PageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; import { @@ -138,12 +138,8 @@ export class DeviceService { return this.http.post(`/api/rpc/twoway/${deviceId}`, requestBody, defaultHttpOptionsFromConfig(config)); } - public getPersistedRpc(rpcId: string, fullResponse = false, - config?: RequestConfig): Observable> { - return this.http.get(`/api/rpc/persistent/${rpcId}`, { - ...defaultHttpOptionsFromConfig(config), - observe: fullResponse ? 'response' : undefined - }); + public getPersistedRpc(rpcId: string, fullResponse = false, config?: RequestConfig): Observable { + return this.http.get(`/api/rpc/persistent/${rpcId}`, defaultHttpOptionsFromConfig(config)); } public findByQuery(query: DeviceSearchQuery,