Client请求外部接口标准处理方式

简单记录下client外部请求代码的我认为比较标准的书写格式

  public List<GdtDailyBalanceReportAO> getGdtDailyReportList2(Long accountId){
        List<GdtDailyBalanceReportAO> listGdtDailyBalance = new ArrayList<>();
        try {
            response = HttpUtil.get(url, null, false);
            log.info("调用 GdtDailyReportClient getGdtDailyReportList accountId:{}, response:{}", accountId, String.valueOf(response));
        } catch (Exception e) {
            log.error("调用GdtDailyReportClient getGdtDailyReportList异常:{}", e);
            e.printStackTrace();
            return listGdtDailyBalance;
        }
        GdtDailyBalanceResponse gdtDailyBalanceResponse = JSON.parseObject(response, GdtDailyBalanceResponse.class);
        if (gdtDailyBalanceResponse.getData() == null || gdtDailyBalanceResponse.getData().getList() == null || gdtDailyBalanceResponse.getData().getList().size() <= 0) {
            log.info("GdtDailyReportClient getGdtDailyReportList response:{},accountId:{}", JSON.toJSONString(gdtDailyBalanceResponse), accountId);
            return listGdtDailyBalance;
        }
    }
posted @ 2022-06-29 09:49  蜗牛使劲冲  阅读(1)  评论(0编辑  收藏  举报  来源