feat: 完成P10生产硬化与矩阵收口(P10E1-P10G1)
这个提交包含在:
@@ -0,0 +1,58 @@
|
||||
const { pushPaidReimbursementToErp } = require("./erp");
|
||||
|
||||
class IntegrationDispatchError extends Error {
|
||||
constructor({ code, message, retryable, statusCode, response }) {
|
||||
super(message || code || "integration_dispatch_failed");
|
||||
this.name = "IntegrationDispatchError";
|
||||
this.code = code || "integration_dispatch_failed";
|
||||
this.retryable = typeof retryable === "boolean" ? retryable : true;
|
||||
this.statusCode = Number.isFinite(statusCode) ? Number(statusCode) : null;
|
||||
this.response = response ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
function toDispatchError(result) {
|
||||
return new IntegrationDispatchError({
|
||||
code: result?.code,
|
||||
message: result?.message,
|
||||
retryable: result?.retryable,
|
||||
statusCode: result?.httpStatus,
|
||||
response: result?.response,
|
||||
});
|
||||
}
|
||||
|
||||
async function dispatchOutboxEvent({ config, eventType, payload }) {
|
||||
if (eventType === "erp.reimbursement.paid") {
|
||||
const result = await pushPaidReimbursementToErp(config, payload);
|
||||
if (!result.ok) {
|
||||
throw toDispatchError(result);
|
||||
}
|
||||
|
||||
return {
|
||||
channel: "erp",
|
||||
code: result.code,
|
||||
response: result.response ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
if (eventType === "notification.im") {
|
||||
return {
|
||||
channel: "im",
|
||||
code: "mock_sent",
|
||||
response: {
|
||||
channelType: payload.channelType,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
throw new IntegrationDispatchError({
|
||||
code: "unsupported_outbox_event",
|
||||
message: `unsupported_outbox_event:${eventType}`,
|
||||
retryable: false,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
IntegrationDispatchError,
|
||||
dispatchOutboxEvent,
|
||||
};
|
||||
在新工单中引用
屏蔽一个用户