Skip to content

Commit

Permalink
Added query info to HomeNotConnectedError.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelamud committed Jan 8, 2023
1 parent bf7adad commit 9f57e0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/api/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Expand Down Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion src/api/node/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ export function* callApi<T>({
errorFilter = false,
onProgress
}: CallApiParams<T>): CallApiResult<T> {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/state/error/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9f57e0b

Please sign in to comment.