mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
allow falsey rpc response (#1680)
* allow falsey rpc response * better check for rpc error and remove extra function Co-authored-by: Matt Hill <matthewonthemoon@gmail.com>
This commit is contained in:
@@ -11,9 +11,7 @@ export class HttpService {
|
||||
async rpcRequest<T>(options: RPCOptions): Promise<T> {
|
||||
const res = await this.httpRequest<RPCResponse<T>>(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<T>(body: RPCOptions): Promise<T> {
|
||||
@@ -31,13 +29,7 @@ export class HttpService {
|
||||
function isRpcError<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { error: Error } {
|
||||
return !!(arg as any).error
|
||||
}
|
||||
|
||||
function isRpcSuccess<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { result: Result } {
|
||||
return !!(arg as any).result
|
||||
return (arg as any).error !== undefined
|
||||
}
|
||||
|
||||
export interface RPCOptions {
|
||||
|
||||
@@ -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<T>(httpOpts: {
|
||||
@@ -132,13 +130,7 @@ class EncryptionError {
|
||||
function isRpcError<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { error: Error } {
|
||||
return !!(arg as any).error
|
||||
}
|
||||
|
||||
function isRpcSuccess<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { result: Result } {
|
||||
return !!(arg as any).result
|
||||
return (arg as any).error !== undefined
|
||||
}
|
||||
|
||||
export enum Method {
|
||||
|
||||
@@ -170,6 +170,7 @@ export class AppConfigPage {
|
||||
} catch (e: any) {
|
||||
this.errToast.present(e)
|
||||
this.saving = false
|
||||
loader.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T>(httpOpts: HttpOptions): Promise<T> {
|
||||
@@ -102,13 +102,7 @@ export class HttpService {
|
||||
function isRpcError<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { error: Error } {
|
||||
return !!(arg as any).error
|
||||
}
|
||||
|
||||
function isRpcSuccess<Error, Result>(
|
||||
arg: { error: Error } | { result: Result },
|
||||
): arg is { result: Result } {
|
||||
return !!(arg as any).result
|
||||
return (arg as any).error !== undefined
|
||||
}
|
||||
|
||||
export interface RequestError {
|
||||
|
||||
Reference in New Issue
Block a user