mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +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> {
|
async rpcRequest<T>(options: RPCOptions): Promise<T> {
|
||||||
const res = await this.httpRequest<RPCResponse<T>>(options)
|
const res = await this.httpRequest<RPCResponse<T>>(options)
|
||||||
if (isRpcError(res)) throw new RpcError(res.error)
|
if (isRpcError(res)) throw new RpcError(res.error)
|
||||||
if (isRpcSuccess(res)) return res.result
|
return res.result
|
||||||
|
|
||||||
throw new Error('Unknown RPC response')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async httpRequest<T>(body: RPCOptions): Promise<T> {
|
async httpRequest<T>(body: RPCOptions): Promise<T> {
|
||||||
@@ -31,13 +29,7 @@ export class HttpService {
|
|||||||
function isRpcError<Error, Result>(
|
function isRpcError<Error, Result>(
|
||||||
arg: { error: Error } | { result: Result },
|
arg: { error: Error } | { result: Result },
|
||||||
): arg is { error: Error } {
|
): arg is { error: Error } {
|
||||||
return !!(arg as any).error
|
return (arg as any).error !== undefined
|
||||||
}
|
|
||||||
|
|
||||||
function isRpcSuccess<Error, Result>(
|
|
||||||
arg: { error: Error } | { result: Result },
|
|
||||||
): arg is { result: Result } {
|
|
||||||
return !!(arg as any).result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RPCOptions {
|
export interface RPCOptions {
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ export class HttpService {
|
|||||||
throw new RpcError(res.error)
|
throw new RpcError(res.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRpcSuccess(res)) return res.result
|
return res.result
|
||||||
|
|
||||||
throw new Error('Unknown RPC response')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async encryptedHttpRequest<T>(httpOpts: {
|
async encryptedHttpRequest<T>(httpOpts: {
|
||||||
@@ -132,13 +130,7 @@ class EncryptionError {
|
|||||||
function isRpcError<Error, Result>(
|
function isRpcError<Error, Result>(
|
||||||
arg: { error: Error } | { result: Result },
|
arg: { error: Error } | { result: Result },
|
||||||
): arg is { error: Error } {
|
): arg is { error: Error } {
|
||||||
return !!(arg as any).error
|
return (arg as any).error !== undefined
|
||||||
}
|
|
||||||
|
|
||||||
function isRpcSuccess<Error, Result>(
|
|
||||||
arg: { error: Error } | { result: Result },
|
|
||||||
): arg is { result: Result } {
|
|
||||||
return !!(arg as any).result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Method {
|
export enum Method {
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ export class AppConfigPage {
|
|||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
this.errToast.present(e)
|
this.errToast.present(e)
|
||||||
this.saving = false
|
this.saving = false
|
||||||
|
loader.dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'
|
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 { map, take } from 'rxjs/operators'
|
||||||
import { ConfigService } from './config.service'
|
import { ConfigService } from './config.service'
|
||||||
import { Revision } from 'patch-db-client'
|
import { Revision } from 'patch-db-client'
|
||||||
@@ -40,7 +40,7 @@ export class HttpService {
|
|||||||
throw new RpcError(res.error)
|
throw new RpcError(res.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRpcSuccess(res)) return res.result
|
return res.result
|
||||||
}
|
}
|
||||||
|
|
||||||
async httpRequest<T>(httpOpts: HttpOptions): Promise<T> {
|
async httpRequest<T>(httpOpts: HttpOptions): Promise<T> {
|
||||||
@@ -102,13 +102,7 @@ export class HttpService {
|
|||||||
function isRpcError<Error, Result>(
|
function isRpcError<Error, Result>(
|
||||||
arg: { error: Error } | { result: Result },
|
arg: { error: Error } | { result: Result },
|
||||||
): arg is { error: Error } {
|
): arg is { error: Error } {
|
||||||
return !!(arg as any).error
|
return (arg as any).error !== undefined
|
||||||
}
|
|
||||||
|
|
||||||
function isRpcSuccess<Error, Result>(
|
|
||||||
arg: { error: Error } | { result: Result },
|
|
||||||
): arg is { result: Result } {
|
|
||||||
return !!(arg as any).result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestError {
|
export interface RequestError {
|
||||||
|
|||||||
Reference in New Issue
Block a user