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

57 lines
1.5 KiB
JavaScript

import { OakException } from 'oak-domain/lib/types';
import makeDepedentException from './DependentExceptions';
export class ExternalPayUtilException extends OakException {
reason;
constructor(reason, message) {
super(message || '调用外部支付渠道接口失败');
this.reason = reason;
}
getSerialData() {
const data = super.getSerialData();
return {
...data,
reason: this.reason,
};
}
}
export class RefundExceedMax extends OakException {
constructor(message) {
super(message || 'error::refund.create.exceedMax');
}
}
export class PayUnRefundable extends OakException {
constructor(message) {
super(message || 'error::refund.create.payUnrefundable');
}
}
export class StartPayFailure extends OakException {
constructor(message) {
super(message);
}
}
export function makeException(msg) {
const data = typeof msg === 'string' ? JSON.parse(msg) : msg;
let exception = makeDepedentException(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;
}