Skip to content

Commit

Permalink
fix(wallet): emit internal error if something broke while broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 25, 2023
1 parent 0dcb239 commit 332d1b5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
1 change: 0 additions & 1 deletion docs/guides/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ BaseError
├── RpcError
│ ├── RpcInvalidTransactionError
│ ├── RpcBroadcastError
│ ├── RpcRejectedByUserError
│ ├── RpcUnsupportedProtocolError
│ ├── RpcConnectionDenyError
Expand Down
6 changes: 2 additions & 4 deletions src/AeSdkWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import verifyTransaction from './tx/validator';
import RpcClient from './aepp-wallet-communication/rpc/RpcClient';
import {
METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,
RpcBroadcastError, RpcInvalidTransactionError,
RpcInvalidTransactionError,
RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,
} from './aepp-wallet-communication/schema';
import { InternalError, UnknownRpcClientError } from './utils/errors';
Expand All @@ -20,7 +20,6 @@ import {
} from './aepp-wallet-communication/rpc/types';
import { Encoded } from './utils/encoder';
import jsonBig from './utils/json-big';
import { ensureError } from './utils/other';

type RpcClientWallet = RpcClient<AeppApi, WalletApi>;

Expand Down Expand Up @@ -260,8 +259,7 @@ export default class AeSdkWallet extends AeSdk {
} catch (error) {
const validation = await verifyTransaction(tx, this.api);
if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
ensureError(error);
throw new RpcBroadcastError(error.message);
throw error;
}
},
[METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {
Expand Down
16 changes: 0 additions & 16 deletions src/aepp-wallet-communication/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@ export class RpcInvalidTransactionError extends RpcError {
}
rpcErrors.push(RpcInvalidTransactionError);

/**
* @category exception
*/
export class RpcBroadcastError extends RpcError {
static override code = 3;

override code = 3;

constructor(data?: any) {
super('Broadcast failed');
this.data = data;
this.name = 'RpcBroadcastError';
}
}
rpcErrors.push(RpcBroadcastError);

/**
* @category exception
*/
Expand Down
18 changes: 18 additions & 0 deletions src/deprecated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RpcError } from './aepp-wallet-communication/schema';

/**
* @category exception
* @deprecated this exception is not thrown anymore
*/
// eslint-disable-next-line import/prefer-default-export
export class RpcBroadcastError extends RpcError {
static override code = 3;

override code = 3;

constructor(data?: any) {
super('Broadcast failed');
this.data = data;
this.name = 'RpcBroadcastError';
}
}
1 change: 1 addition & 0 deletions src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export { default as walletDetector } from './aepp-wallet-communication/wallet-de
export { default as BrowserRuntimeConnection } from './aepp-wallet-communication/connection/BrowserRuntime';
export { default as BrowserWindowMessageConnection } from './aepp-wallet-communication/connection/BrowserWindowMessage';
export * from './utils/errors';
export * from './deprecated';

0 comments on commit 332d1b5

Please sign in to comment.