mcps-sdk-js
Version:
MCPS JavaScript SDK
103 lines (97 loc) • 3.27 kB
text/typescript
const CODESPACE_ROOT = 'sdk';
/** Error codes in mcps v1.0 */
export const CODES = {
OK: 0,
Internal: 1,
TxDecode: 2,
InvalidSequence: 3,
Unauthorized: 4,
InsufficientFunds: 5,
UnknownRequest: 6,
InvalidAddress: 7,
InvalidPubkey: 8,
UnknownAddress: 9,
InvalidCoins: 10,
OutOfGas: 11,
MemoTooLarge: 12,
InsufficientFee: 13,
OutOfService: 15,
TooManySignatures: 14,
NoSignatures: 15,
ErrJsonMarshal: 16,
ErrJsonUnmarshal: 17,
InvalidRequest: 18,
TxInMempoolCache: 19,
MempoolIsFull: 20,
TxTooLarge: 21,
};
/** Error codes in mcps v0.17 */
const CODES_V17 = {
OK: 0,
Internal: 1,
TxDecode: 2,
InvalidSequence: 3,
Unauthorized: 4,
InsufficientFunds: 5,
UnknownRequest: 6,
InvalidAddress: 7,
InvalidPubkey: 8,
UnknownAddress: 9,
InsufficientCoins: 10,
InvalidCoins: 11,
OutOfGas: 12,
MemoTooLarge: 13,
InsufficientFee: 14,
OutOfService: 15,
TooManySignatures: 16,
GasPriceTooLow: 17,
InvalidGas: 18,
InvalidTxFee: 19,
InvalidFeeDenom: 20,
ExceedsTxSize: 21,
ServiceTxLimit: 22,
PaginationParams: 23,
};
// Map error codes in mcps v0.17 to v1.0
const errorMap = new Map<string, number>([
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ], // Unused
[ ],
[ ],
[ ],
[ ],
[ ], // Only used in ValidateFee for genesis
[ ],
[ ],
[ ],
]);
/** MCPS SDK Error */
export class SdkError extends Error {
/** Error code space, reserved field */
codespace = CODESPACE_ROOT;
/** Error code */
code = CODES.InvalidRequest;
/**
* Initialize SdkError with mcps error msg
* @param msg mcps error msg
*/
constructor(msg: string, code = CODES.InvalidRequest) {
super(msg);
// const mappedCode = errorMap.get(this.codespace + code);
this.code = code;
}
}