OBP 수수료 연동시 에러 메세지 개선
This commit is contained in:
+14
@@ -64,6 +64,10 @@ public class CommissionController {
|
||||
String obmUrl = portalPropertyService.getPortalPropertiesAsMap("Portal").getOrDefault("obp.obm.url", "");
|
||||
String url = obmUrl + Constants.COMMISSION_PRINT_URL;
|
||||
String result = externalService.getResponseHttpPost(url, toJson(search));
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
model.addAttribute("error", "외부 서버 연결에 실패하였습니다.");
|
||||
return "apps/commission/commissionPrint";
|
||||
}
|
||||
HashMap<String, Object> returnObj = new ObjectMapper().readValue(result, HashMap.class);
|
||||
|
||||
if (!StringUtils.isEmpty(returnObj.get("error"))) {
|
||||
@@ -76,6 +80,10 @@ public class CommissionController {
|
||||
log.debug("Found Together : " + search.getPartnerCode());
|
||||
search.setPartnerCode("000002-02");
|
||||
String togetherResult = externalService.getResponseHttpPost(url, toJson(search));
|
||||
if (StringUtils.isEmpty(togetherResult)) {
|
||||
model.addAttribute("error", "외부 서버 연결에 실패하였습니다.");
|
||||
return "apps/commission/commissionPrint";
|
||||
}
|
||||
|
||||
HashMap togetherLendingReturnObj = new ObjectMapper().readValue(togetherResult, HashMap.class);
|
||||
log.debug("togetherLendingReturnObj : " + togetherLendingReturnObj.toString());
|
||||
@@ -118,6 +126,9 @@ public class CommissionController {
|
||||
String obmUrl = portalPropertyService.getPortalPropertiesAsMap("Portal").getOrDefault("obp.obm.url", "");
|
||||
String url = obmUrl + Constants.COMMISSION_URL;
|
||||
String result = externalService.getResponseHttpPost(url, toJson(search));
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
return ErrorUtil.create("fail.commission.serverError", "외부 서버 연결에 실패하였습니다.");
|
||||
}
|
||||
HashMap<String, Object> returnObj = new ObjectMapper().readValue(result, HashMap.class);
|
||||
if (!StringUtils.isEmpty(returnObj.get("error"))) {
|
||||
HashMap<String, Object> error = (HashMap) returnObj.get("error");
|
||||
@@ -128,6 +139,9 @@ public class CommissionController {
|
||||
log.debug("Found Together : " + search.getPartnerCode());
|
||||
search.setPartnerCode("000002-02");
|
||||
String togetherResult = externalService.getResponseHttpPost(url, toJson(search));
|
||||
if (StringUtils.isEmpty(togetherResult)) {
|
||||
return ErrorUtil.create("fail.commission.serverError", "외부 서버 연결에 실패하였습니다.");
|
||||
}
|
||||
|
||||
HashMap<String, Object> togetherLendingReturnObj = new ObjectMapper().readValue(togetherResult, HashMap.class);
|
||||
log.debug("togetherLendingReturnObj : " + togetherLendingReturnObj.toString());
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@@ -60,6 +61,14 @@ public class ExternalService {
|
||||
// 응답 본문 반환
|
||||
return response.getBody();
|
||||
|
||||
} catch (HttpStatusCodeException e) {
|
||||
// 4xx, 5xx 에러더라도 응답 본문이 있으면 반환 (에러 메시지 포함)
|
||||
String responseBody = e.getResponseBodyAsString();
|
||||
log.warn("HTTP error from external API: url={}, status={}, body={}", url, e.getStatusCode(), responseBody);
|
||||
if (responseBody != null && !responseBody.isEmpty()) {
|
||||
return responseBody;
|
||||
}
|
||||
return null;
|
||||
} catch (RestClientException e) {
|
||||
log.error("Failed to call external API: url={}, error={}", url, e.getMessage(), e);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user