Customizing Zuul Exception

后端 未结 7 1118
说谎
说谎 2020-11-29 05:23

I have a scenario in Zuul where the service that the URL is routed too might be down . So the reponse body gets thrown with 500 HTTP Status and ZuulException in the JSON bod

相关标签:
7条回答
  • 2020-11-29 06:02

    I had the same problem and was able to solve it in simpler way

    Just put this into you Filter run() method

        if (<your condition>) {
            ZuulException zuulException = new ZuulException("User message", statusCode, "Error Details message");
            throw new ZuulRuntimeException(zuulException);
        }
    

    and SendErrorFilter will deliver to the user the message with the desired statusCode.

    This Exception in an Exception pattern does not look exactly nice, but it works here.

    0 讨论(0)
提交回复
热议问题