有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

伪错误解码器中的java响应未获取Zalando问题自定义属性

我有两个Spring引导组件,一个是被请求的服务,另一个是通过外部客户端发送请求的主组件。服务组件使用Zalando问题构建异常,并将其映射到主组件错误解码器中的结构中

我的服务组件问题创建(在kotlin中):

    @ExceptionHandler
fun handle(ex: ErrorException, request: NativeWebRequest): ResponseEntity<Problem> {

    return when (ex.code) {

        ErrorCodes.OPERATION_NOT_ALLOWED,
        ErrorCodes.QUERY_ERROR -> create(Status.BAD_REQUEST, Problem.builder()
                .withDetail(ex.message)
                .with("code", ex.code.name)
                .withStatus(Status.BAD_REQUEST)
                .build(), request)
    }
}

主组件中的My error decoder类:

public class ClientErrorDecoder implements ErrorDecoder {
private final ObjectMapper mapper = new ObjectMapper();

@Override
public Exception decode(String methodKey, Response response) {
    try {
        ClientExceptionDTO clientExDTO = mapper.readValue(response.body().asInputStream(), ClientExDTO.class);
        log.debug("Exception from external service: " + clientExDTO);
        return new ErrorException(clientExDTO.getDetail(), ErrorCodes.EXTERNAL_SERVICE_ERROR);
    } catch (IOException e) {
        throw new ErrorException("Failed to process response body.", ErrorCodes.UNPROCESSABLE_RESPONSE);
    }
}

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
private static class ClientExDTO {
    private String title;
    private String code;
    private String detail;
    private String status;
    
}

}

我遇到的问题是主组件的响应对象不包含自定义属性“code”: {"title":"Bad Request","status":400,"detail":"Exception occurred in ext service"}

我在Zalando问题和外国客户方面遗漏了什么


共 (0) 个答案