"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPolymeshError = exports.PolymeshError = void 0;
const types_1 = require("../types");
const defaultMessages = {
    [types_1.ErrorCode.TransactionReverted]: 'The transaction execution reverted due to an error',
    [types_1.ErrorCode.TransactionAborted]: 'The transaction was removed from the transaction pool. This might mean that it was malformed (nonce too large/nonce too small/duplicated or invalid transaction)',
    [types_1.ErrorCode.TransactionRejectedByUser]: 'The user canceled the transaction signature',
};
/**
 * Wraps an error to give more information about its type
 */
class PolymeshError extends Error {
    /**
     * @hidden
     */
    constructor({ message, code, data, }) {
        super(message || defaultMessages[code] || `Unknown error, code: ${code}`);
        this.code = code || types_1.ErrorCode.FatalError;
        this.data = data;
    }
}
exports.PolymeshError = PolymeshError;
/**
 * @hidden
 */
function isPolymeshError(err) {
    const error = err;
    return typeof error.code === 'string' && typeof error.message === 'string';
}
exports.isPolymeshError = isPolymeshError;
//# sourceMappingURL=PolymeshError.js.map