HTTP 204处理

时间:2019-07-05 14:42:26

标签: java spring-boot http exception

我添加了代码来处理下面的代码允许的http响应。

        // Map response to List of OutputDtos, response
    if (HttpStatus.OK == responseEntity.getStatusCode() || HttpStatus.NO_CONTENT == responseEntity.getStatusCode()) {

        if (HttpStatus.NO_CONTENT == responseEntity.getStatusCode()) {

            response = new ArrayList<>();
        } else {
            ObjectMapper mapper = new ObjectMapper();
            try {
                response = mapper.readValue(responseEntity.getBody().toString(),
                        new TypeReference<List<OutputDto>>() {
                        });
            } catch (IOException e) {
                String message = "Something went wrong while parsing responseEntity.";
                LOGGER.error(message, e);
                throw new CustomException(message, e);              }
        }
    } else {
        String msg = "Response from service was not OK: " + responseEntity;
        LOGGER.error(msg);
        throw new CustomException(msg);
    }

    return response;
}

我的springboot应用程序以前在接收204时崩溃,并且仅在获取200时崩溃。在调试中,我看到接收200时列表已正确填充。如果Http 204响应,我添加了此代码以创建一个空列表收到,但似乎运行无限循环。我没有看到我的错误。

0 个答案:

没有答案