From 908a945b95da4e2947608d406300b5f4f1259cff Mon Sep 17 00:00:00 2001 From: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com> Date: Mon, 25 Jul 2022 10:16:04 -0600 Subject: [PATCH] allow falsey rpc response (#1680) * allow falsey rpc response * better check for rpc error and remove extra function Co-authored-by: Matt Hill --- .../diagnostic-ui/src/app/services/http.service.ts | 12 ++---------- .../src/app/services/api/http.service.ts | 12 ++---------- .../ui/src/app/modals/app-config/app-config.page.ts | 1 + .../projects/ui/src/app/services/http.service.ts | 12 +++--------- 4 files changed, 8 insertions(+), 29 deletions(-) diff --git a/frontend/projects/diagnostic-ui/src/app/services/http.service.ts b/frontend/projects/diagnostic-ui/src/app/services/http.service.ts index 3a57d0844..da774aa37 100644 --- a/frontend/projects/diagnostic-ui/src/app/services/http.service.ts +++ b/frontend/projects/diagnostic-ui/src/app/services/http.service.ts @@ -11,9 +11,7 @@ export class HttpService { async rpcRequest(options: RPCOptions): Promise { const res = await this.httpRequest>(options) if (isRpcError(res)) throw new RpcError(res.error) - if (isRpcSuccess(res)) return res.result - - throw new Error('Unknown RPC response') + return res.result } async httpRequest(body: RPCOptions): Promise { @@ -31,13 +29,7 @@ export class HttpService { function isRpcError( arg: { error: Error } | { result: Result }, ): arg is { error: Error } { - return !!(arg as any).error -} - -function isRpcSuccess( - arg: { error: Error } | { result: Result }, -): arg is { result: Result } { - return !!(arg as any).result + return (arg as any).error !== undefined } export interface RPCOptions { diff --git a/frontend/projects/setup-wizard/src/app/services/api/http.service.ts b/frontend/projects/setup-wizard/src/app/services/api/http.service.ts index 1ac4505be..84d2a4fb7 100644 --- a/frontend/projects/setup-wizard/src/app/services/api/http.service.ts +++ b/frontend/projects/setup-wizard/src/app/services/api/http.service.ts @@ -42,9 +42,7 @@ export class HttpService { throw new RpcError(res.error) } - if (isRpcSuccess(res)) return res.result - - throw new Error('Unknown RPC response') + return res.result } async encryptedHttpRequest(httpOpts: { @@ -132,13 +130,7 @@ class EncryptionError { function isRpcError( arg: { error: Error } | { result: Result }, ): arg is { error: Error } { - return !!(arg as any).error -} - -function isRpcSuccess( - arg: { error: Error } | { result: Result }, -): arg is { result: Result } { - return !!(arg as any).result + return (arg as any).error !== undefined } export enum Method { diff --git a/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts b/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts index 0cbfb8690..3bc834d87 100644 --- a/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts +++ b/frontend/projects/ui/src/app/modals/app-config/app-config.page.ts @@ -170,6 +170,7 @@ export class AppConfigPage { } catch (e: any) { this.errToast.present(e) this.saving = false + loader.dismiss() } } diff --git a/frontend/projects/ui/src/app/services/http.service.ts b/frontend/projects/ui/src/app/services/http.service.ts index a4d4e53c8..40e6a300d 100644 --- a/frontend/projects/ui/src/app/services/http.service.ts +++ b/frontend/projects/ui/src/app/services/http.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core' import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' -import { Observable, from, interval, race } from 'rxjs' +import { from, interval, Observable, race } from 'rxjs' import { map, take } from 'rxjs/operators' import { ConfigService } from './config.service' import { Revision } from 'patch-db-client' @@ -40,7 +40,7 @@ export class HttpService { throw new RpcError(res.error) } - if (isRpcSuccess(res)) return res.result + return res.result } async httpRequest(httpOpts: HttpOptions): Promise { @@ -102,13 +102,7 @@ export class HttpService { function isRpcError( arg: { error: Error } | { result: Result }, ): arg is { error: Error } { - return !!(arg as any).error -} - -function isRpcSuccess( - arg: { error: Error } | { result: Result }, -): arg is { result: Result } { - return !!(arg as any).result + return (arg as any).error !== undefined } export interface RequestError {