Skip to content

Commit

Permalink
improve error messages for connection failures and failed LNDHub auth…
Browse files Browse the repository at this point in the history
…entication
  • Loading branch information
myxmaster committed Dec 23, 2024
1 parent 9042771 commit f5f2b6e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1080,12 +1080,14 @@
"stores.SettingsStore.lndhubSuccess": "Successfully created LNDHub account. Record the username and password somewhere so you can restore your funds if something happens to your device. Then hit Save Wallet Config to continue.",
"stores.SettingsStore.lndhubError": "Error creating LNDHub account. Please check the host and try again.",
"stores.SettingsStore.lndhubLoginError": "Failed to log in to LNDHub server",
"stores.SettingsStore.lndhubConnectError": "Unable to connect to LNDHub server. Please verify the host address is correct and the service is running.",
"stores.SettingsStore.lncConnectError": "Failed to connect the LNC client to the proxy server",
"stores.LSPStore.error": "LSP error",
"stores.LSPStore.connectionError": "Could not connect to LSP. Please check your LSP settings or try again later.",
"stores.LightningAddressStore.preimageNotFound": "Pre-image not found on your device. Did you recently change devices?",
"error.connectionRefused": "Host unreachable. Try restarting your node or its Tor process.",
"error.hostUnreachable": "Host unreachable. Try restarting your node or its Tor process.",
"error.nodeConnectError": "Unable to connect to node. Please verify the host and port are correct and the service is running.",
"error.torBootstrap": "Error starting up Tor on your phone. Try restarting Zeus. If the problem persists consider using the Orbot app to connect to Tor, or using an alternative connection method like Lightning Node Connect or Tailscale.",
"error.sendingPayment": "Error sending payment",
"error.failureReasonTimeout": "There are more routes to try, but the payment timeout was exceeded.",
Expand Down
18 changes: 13 additions & 5 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1767,13 +1767,21 @@ export default class SettingsStore {
this.refreshToken = data.refresh_token;
resolve(data);
})
.catch(() => {
// handle error
.catch((error: any) => {
this.loading = false;
this.error = true;
this.errorMsg = localeString(
'stores.SettingsStore.lndhubLoginError'
);
if (
typeof error.message === 'string' &&
error.message.includes('"bad auth"')
) {
this.errorMsg = localeString(
'stores.SettingsStore.lndhubLoginError'
);
} else {
this.errorMsg = localeString(
'stores.SettingsStore.lndhubConnectError'
);
}
resolve();
});
});
Expand Down
2 changes: 1 addition & 1 deletion stores/TransactionsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export default class TransactionsStore {
const isKeysend =
result?.htlcs?.[0]?.route?.hops?.[0]?.custom_records?.[
keySendPreimageType
];
] != null;

// TODO add message for in-flight transactions
if (
Expand Down
20 changes: 16 additions & 4 deletions utils/ErrorUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { errorToUserFriendly } from './ErrorUtils';

jest.mock('./LocaleUtils', () => ({
localeString: (key: string) => {
const EN = require('../locales/en.json');
return EN[key];
}
localeString: (key: string) => require('../locales/en.json')[key]
}));

describe('ErrorUtils', () => {
Expand Down Expand Up @@ -98,6 +95,21 @@ describe('ErrorUtils', () => {
);
});

it('Handles partial error message matches', () => {
expect(
errorToUserFriendly(
Object.assign(new Error(), {
message:
'Error: Failed to connect to /can-be-any-host:8082',
name: 'test'
}),
false
)
).toEqual(
'Unable to connect to node. Please verify the host and port are correct and the service is running.'
);
});

it('Returns normal error message for unhandled errorContext', () => {
expect(
errorToUserFriendly(
Expand Down
20 changes: 14 additions & 6 deletions utils/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const userFriendlyErrors: any = {
'error.torBootstrap',
'Error: called `Result::unwrap()` on an `Err` value: BootStrapError("Timeout waiting for boostrap")':
'error.torBootstrap',
'Error: Failed to connect to': 'error.nodeConnectError',
'Error: Unable to resolve host': 'error.nodeConnectError',
FAILURE_REASON_TIMEOUT: 'error.failureReasonTimeout',
FAILURE_REASON_NO_ROUTE: 'error.failureReasonNoRoute',
FAILURE_REASON_ERROR: 'error.failureReasonError',
Expand Down Expand Up @@ -48,13 +50,19 @@ const errorToUserFriendly = (
errorMsg = errorMsg.charAt(0).toUpperCase() + errorMsg.slice(1);
}

const matchingPattern = Object.keys(userFriendlyErrors).find((pattern) =>
errorMsg.includes(pattern)
);

let localeKey = matchingPattern
? userFriendlyErrors[matchingPattern]
: null;

if (localize) {
const localeString = require('./LocaleUtils').localeString;
let baseError =
localeString(userFriendlyErrors[errorMsg])?.replace(
'Zeus',
'ZEUS'
) || errorMsg;
let baseError = localeKey
? localeString(localeKey)?.replace('Zeus', 'ZEUS')
: errorMsg;

if (
errorContext?.includes('Keysend') &&
Expand All @@ -69,7 +77,7 @@ const errorToUserFriendly = (
return baseError;
} else {
const EN = require('../locales/en.json');
return EN[userFriendlyErrors[errorMsg]] || errorMsg;
return localeKey ? EN[localeKey] : errorMsg;
}
};

Expand Down

0 comments on commit f5f2b6e

Please sign in to comment.