我在休息架構中使用彈簧引導。 我是一名具有錯誤管理的新手。錯誤管理
我的代碼有這樣的結構
@Transactional
@Override
public void processPayment() throws CreditCardPaymentException{
List<Payment> payments = paymentRepository.findByDateLessThanEqualAndPaymentModeAndStatus(LocalDate.now(), PaymentModeEnum.CREDITCARD, StatusEnum.STANDBY);
processCreditCardPayment(payments);
}
private void processCreditCardPayment(List<Payment> payments) throws ProcessPaymentException{
PaymentGatewayConfig paymentGateway = new PaymentGatewayConfig();
String crypt_type = "7";
for (Payment payment : payments) {
chargeMemberCreditCard(payment, crypt_type, paymentGateway);
}
}
private ResolverReceipt chargeMemberCreditCard(Payment payment, String crypt_type, PaymentGatewayConfig paymentGateway) throws ProcessPaymentException {
try {
if (resreceipt != null) {
//information about customer we have sent are returned
ResolveData resdata = resreceipt.getResolveData();
//todo check auth code
if (Boolean.valueOf(resreceipt.getComplete()) && !Boolean.valueOf(resreceipt.getTimedOut())) {
//if (resreceipt != null && resreceipt.getResponseCode() != null && Integer.getInteger(resreceipt.getResponseCode()) < 50) {
payment.setStatus(StatusEnum.COMPLETE);
} else {
payment.setStatus(StatusEnum.FAIL);
}
}
} catch (Exception e) {
throw new ProcessPaymentException();
log.error("chargeMemberCreditCard - payment: " + payment.getPaymentId(), e);
}
}
如果有錯誤付款,我想傳遞給下一個。 如果最後有很多錯誤,我只想知道發生了什麼錯誤。
不知道是否該走的路,如果這段代碼會這樣做。
try/catch語句與失敗的列表失敗
Payments
或Exceptions
? –