From 9f57e0b504763dcc6d05e6d4c1239f529737e28f Mon Sep 17 00:00:00 2001 From: Shmuel Melamud Date: Sun, 8 Jan 2023 02:09:36 +0200 Subject: [PATCH] Added query info to HomeNotConnectedError. --- src/api/error.ts | 10 +++++++--- src/api/node/call.ts | 11 ++++++++++- src/state/error/reducer.ts | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/api/error.ts b/src/api/error.ts index 98679c197..0e811c9d2 100644 --- a/src/api/error.ts +++ b/src/api/error.ts @@ -16,9 +16,9 @@ export class VerboseError extends Error { messageVerbose: string; - constructor(message: string, messageVerbose: string) { + constructor(message: string, messageVerbose: string | null = null) { super(message); - this.messageVerbose = messageVerbose; + this.messageVerbose = messageVerbose ?? message; } } @@ -65,12 +65,16 @@ export class NodeApiError extends Error { } -export class HomeNotConnectedError extends Error { +export class HomeNotConnectedError extends VerboseError { constructor() { super("Not connected to home"); } + setQuery(method: string, location: string): void { + this.messageVerbose = `${method} ${location}: ${this.message}` + } + } export class NameResolvingError extends Error { diff --git a/src/api/node/call.ts b/src/api/node/call.ts index 6d981e547..ec7b44b33 100644 --- a/src/api/node/call.ts +++ b/src/api/node/call.ts @@ -67,7 +67,16 @@ export function* callApi({ errorFilter = false, onProgress }: CallApiParams): CallApiResult { - const {rootLocation, rootApi, errorTitle} = yield* call(selectApi, nodeName); + let api: ApiSelection = {rootLocation: null, rootApi: "", errorTitle: ""}; + try { + api = yield* call(selectApi, nodeName); + } catch (e) { + if (e instanceof HomeNotConnectedError) { + e.setQuery(method ?? "", location); + } + throw e; + } + const {rootLocation, rootApi, errorTitle} = api; if (!rootLocation) { throw new NameResolvingError(nodeName); } diff --git a/src/state/error/reducer.ts b/src/state/error/reducer.ts index 8084eb033..62c0e29fb 100644 --- a/src/state/error/reducer.ts +++ b/src/state/error/reducer.ts @@ -14,7 +14,7 @@ export default (state: ErrorState = initialState, action: ClientAction): ErrorSt const {message, messageVerbose} = action.payload; return { message: message, - messageVerbose: messageVerbose ? messageVerbose : message, + messageVerbose: messageVerbose ?? message, visible: true }; case ERROR_DISMISS: