/**
 * 异常模块
 * @date 2022-03
 * @author 何华东
 */

/**
 * 参数异常
 * @param message 异常信息
 * @param paramName 参数名
 */
export class ParamError extends Error {
    paramName: string;

    constructor(message: string, paramName: string) {
        super();

        this.name = this.constructor.name;
        this.message = message;
        this.paramName = paramName;
    }
}

/**
 * 参数无效异常
 * @param paramName 参数名
 */
export class ParamInvalidError extends ParamError {
    constructor(paramName: string) {
        super(`invalid ${paramName}.`, paramName);

        this.name = this.constructor.name;
    }
}

/**
 * 参数为空异常
 * @param paramName 参数名
 */
export class ParamEmptyError extends ParamError {
    constructor(paramName?: string) {
        super(`${paramName || 'param'} is empty.`, paramName);

        this.name = this.constructor.name;
    }
}

/**
 * 参数解密失败异常
 * @param paramName 参数名
 */
export class ParamDecryptFailedError extends ParamError {
    constructor(paramName?: string) {
        super(`${paramName || 'param'} decrypt failed.`, paramName);

        this.name = this.constructor.name;
    }
}

/**
 * 验签失败异常
 */
export class ValidateSignFailedError extends Error {
    constructor() {
        super('validate sign failed.');
        
        this.name = this.constructor.name;
    }
}