Can I override RESTClient default “HttpResponseException” response to >399 Return Codes?

廉价感情. 提交于 2019-12-03 10:53:44
Jon Peterson

As Tomasz already linked in a comment, here is my little one-liner answer from a similar question.

client.handler.failure = client.handler.success
Zach Lysobey

@JonPeterson came up with what I think is a better solution, so I gave his answer the checkmark:

client.handler.failure = client.handler.success

More info here


The solution I (previously) landed on:

 restClient.handler.failure = { it }

Which is shorthand for

restClient.handler.failure = { resp -> return resp }

@JimmyLuong noted in the comments that this approach drops the data from the response, and suggested the following enhancement:

 restClient.handler.failure = { resp, data -> resp.setData(data); return resp }

One approach would be to make a Groovy convenience method that wraps your REST calls that catches exceptions and turns them into status codes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!