Skip to content

Commit

Permalink
Merge branch 'fix/wallet-package-deps' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Oct 29, 2024
2 parents b484c80 + 8c7ef36 commit b1c3008
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 254 deletions.
31 changes: 31 additions & 0 deletions packages/exceptions/src/exceptions/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { GrpcUnaryRequestException } from './GrpcUnaryRequestException'
import { HttpRequestException } from './HttpRequestException'
import { Web3Exception } from './Web3Exception'
import { GeneralException } from './GeneralException'
import { LedgerException } from './LedgerException'
import { LedgerCosmosException } from './LedgerCosmosException'
import { MetamaskException } from './MetamaskException'
import { TrustWalletException } from './TrustWalletException'
import { OkxWalletException } from './OkxWalletException'
import { TrezorException } from './TrezorException'
import { CosmosWalletException } from './CosmosWalletException'
import { TransactionException } from './TransactionException'
import { WalletException } from './WalletException'
import { BitGetException } from './BitGetException'

export {
Web3Exception,
LedgerException,
TrezorException,
WalletException,
GeneralException,
BitGetException,
MetamaskException,
TransactionException,
TrustWalletException,
OkxWalletException,
HttpRequestException,
LedgerCosmosException,
CosmosWalletException,
GrpcUnaryRequestException,
}
81 changes: 3 additions & 78 deletions packages/exceptions/src/exceptions/index.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
import { GrpcUnaryRequestException } from './GrpcUnaryRequestException'
import { HttpRequestException } from './HttpRequestException'
import { Web3Exception } from './Web3Exception'
import { GeneralException } from './GeneralException'
import { LedgerException } from './LedgerException'
import { LedgerCosmosException } from './LedgerCosmosException'
import { MetamaskException } from './MetamaskException'
import { TrustWalletException } from './TrustWalletException'
import { OkxWalletException } from './OkxWalletException'
import { TrezorException } from './TrezorException'
import { CosmosWalletException } from './CosmosWalletException'
import { TransactionException } from './TransactionException'
import { WalletException } from './WalletException'
import { Exception } from '../types'
import { ConcreteException } from '../exception'
import { BitGetException } from './BitGetException'

export type ThrownException =
| GrpcUnaryRequestException
| HttpRequestException
| Web3Exception
| GeneralException
| LedgerException
| MetamaskException
| TrustWalletException
| OkxWalletException
| TrezorException
| CosmosWalletException
| TransactionException
| WalletException
| LedgerCosmosException
| BitGetException

export const isThrownException = (exception: Error | Exception): boolean => {
if (exception instanceof ConcreteException) {
return true
}

if (
[
'GrpcUnaryRequestException',
'HttpRequestException',
'Web3Exception',
'GeneralException',
'LedgerException',
'LedgerCosmosException',
'MetamaskException',
'TrezorException',
'CosmosWalletException',
'TransactionException',
'WalletException',
'TrustWalletException',
'OkxWalletException',
'BitGetException',
].includes(exception.constructor.name)
) {
return true
}

return false
}

export {
Web3Exception,
LedgerException,
TrezorException,
WalletException,
GeneralException,
BitGetException,
MetamaskException,
TransactionException,
TrustWalletException,
OkxWalletException,
HttpRequestException,
LedgerCosmosException,
CosmosWalletException,
GrpcUnaryRequestException,
}
export * from './exceptions'
export * from './types'
export * from './utils'
32 changes: 32 additions & 0 deletions packages/exceptions/src/exceptions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
Web3Exception,
WalletException,
TrezorException,
BitGetException,
LedgerException,
GeneralException,
MetamaskException,
OkxWalletException,
HttpRequestException,
LedgerCosmosException,
TrustWalletException,
CosmosWalletException,
TransactionException,
GrpcUnaryRequestException,
} from './exceptions'

export type ThrownException =
| GrpcUnaryRequestException
| HttpRequestException
| Web3Exception
| GeneralException
| LedgerException
| MetamaskException
| TrustWalletException
| OkxWalletException
| TrezorException
| CosmosWalletException
| TransactionException
| WalletException
| LedgerCosmosException
| BitGetException
31 changes: 31 additions & 0 deletions packages/exceptions/src/exceptions/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ConcreteException } from "../exception"
import { Exception } from "../types"

export const isThrownException = (exception: Error | Exception): boolean => {
if (exception instanceof ConcreteException) {
return true
}

if (
[
'GrpcUnaryRequestException',
'HttpRequestException',
'Web3Exception',
'GeneralException',
'LedgerException',
'LedgerCosmosException',
'MetamaskException',
'TrezorException',
'CosmosWalletException',
'TransactionException',
'WalletException',
'TrustWalletException',
'OkxWalletException',
'BitGetException',
].includes(exception.constructor.name)
) {
return true
}

return false
}
111 changes: 111 additions & 0 deletions packages/exceptions/src/types/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { ErrorCode, ErrorContextCode } from './codes'

export enum HttpRequestMethod {
Get = 'GET',
Post = 'POST',
Options = 'OPTIONS',
}

export enum ErrorType {
Unspecified = 'unspecified',
ChainError = 'chain-error',
ExecutionError = 'execution-error',
NotFoundError = 'not-found-error',
ValidationError = 'validation-error',
WalletError = 'wallet-error',
WalletNotInstalledError = 'wallet-not-installed-error',
GrpcUnaryRequest = 'grpc-unary-request',
HttpRequest = 'http-request',
Web3 = 'web3',
Web3Gateway = 'web3-gateway',
}

export interface ErrorContext {
code?: ErrorCode
type?: ErrorType

/**
* Additional context needed for the exception
*/
context?: string

/**
* Where is the exception thrown
*/
contextModule?: string

/**
* Needed when we get a code error from a Http/Grpc Request
* and we need to specify the error code for the particular message
* for example why the transaction has failed
* */
contextCode?: ErrorContextCode
}

export interface Exception {
/**
* The type of the Error
*/
type: ErrorType

/**
* Error specific code (HttpStatus, GrpcStatus, etc)
*/
code: ErrorCode

/**
* The name of the error (the name of the instance of the Exception)
*/
name: string

/**
* Providing more context as to where the exception was thrown
* (ex: on-chain module, etc)
*/
contextModule?: string

/**
* Providing more context as to why the exception was thrown
* (ex: on-chain error code, etc)
*/
contextCode?: ErrorContextCode

/**
* Parsed message of the exception
*/
message: string

/**
* The original stack of the error
*/
stack?: string

/**
* The original message of the error
*/
originalMessage: string

parse?(): void

parseError(error: Error): void

parseContext(context?: ErrorContext): void

setType(type: ErrorType): void

setCode(code: ErrorCode): void

setStack(stack: string): void

setName(name: string): void

setMessage(message: string): void

setContextModule(contextModule: string): void

toOriginalError(): Error

toError(): Error

toString(): string
}
Loading

0 comments on commit b1c3008

Please sign in to comment.