Java 从外部响应获取未编码的消息
我有一个POST方法,成功时返回Java 从外部响应获取未编码的消息,java,spring-boot,spring-cloud-feign,feign,Java,Spring Boot,Spring Cloud Feign,Feign,我有一个POST方法,成功时返回JSON响应,错误时返回application/x-www-form-urlencoded @PostMapping(path = SUBSCRIBE_PATH, consumes = APPLICATION_JSON_VALUE) MySubscribeRs subscribe(@RequestHeader("Api-Key") String apiKey, @Reque
JSON
响应,错误时返回application/x-www-form-urlencoded
@PostMapping(path = SUBSCRIBE_PATH, consumes = APPLICATION_JSON_VALUE)
MySubscribeRs subscribe(@RequestHeader("Api-Key") String apiKey,
@RequestBody String requestBody);
下面是一个错误示例:
400 Bad request
["The user already has a subscription"]
我捕获了FaignException,其中包含详细信息:
[400 Bad Request] during [POST] to [http://localhost:11619/api/cb/payments/subscribe/] [MyFeignRestClient#subscribe(String,String)]: [["The user already has a subscription"]]
如何在不解析字符串的情况下获取
“用户已经有订阅”
消息?如果REST调用没有返回JSON响应,而是返回异常消息,则需要解析异常消息。exception.getMessage()返回什么?@SusanMustafa我在帖子中描述了它,您需要解析它