oak-pay-business/lib/types/Exception.js

66 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeException = exports.StartPayFailure = exports.PayUnRefundable = exports.RefundExceedMax = exports.ExternalPayUtilException = void 0;
const tslib_1 = require("tslib");
const types_1 = require("oak-domain/lib/types");
const DependentExceptions_1 = tslib_1.__importDefault(require("./DependentExceptions"));
class ExternalPayUtilException extends types_1.OakException {
reason;
constructor(reason, message) {
super(message || '调用外部支付渠道接口失败');
this.reason = reason;
}
getSerialData() {
const data = super.getSerialData();
return {
...data,
reason: this.reason,
};
}
}
exports.ExternalPayUtilException = ExternalPayUtilException;
class RefundExceedMax extends types_1.OakException {
constructor(message) {
super(message || 'error::refund.create.exceedMax');
}
}
exports.RefundExceedMax = RefundExceedMax;
class PayUnRefundable extends types_1.OakException {
constructor(message) {
super(message || 'error::refund.create.payUnrefundable');
}
}
exports.PayUnRefundable = PayUnRefundable;
class StartPayFailure extends types_1.OakException {
constructor(message) {
super(message);
}
}
exports.StartPayFailure = StartPayFailure;
function makeException(msg) {
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
let exception = (0, DependentExceptions_1.default)(data);
if (exception) {
return exception;
}
const { name, message } = data;
switch (name) {
case 'ExternalPrePayException': {
exception = new ExternalPayUtilException(data.reason, message);
break;
}
case 'RefundExceedMax': {
exception = new RefundExceedMax(message);
break;
}
default: {
break;
}
}
if (exception) {
exception.setOpRecords(data.opRecords);
}
return exception;
}
exports.makeException = makeException;