Question one,
In actual use zuul found a problem when routing address can not reach, zuul throw Filter threw Exception, shielding the actual error.
By reading the source code available, Zuul ZuulException exception will be thrown, will be encapsulated within RunTimeException.
Throwable need to use interceptors capture.
Question two,
The above code derived from com.netflix.zuul.http.ZuulServlet
the service
method of implementation that defines processing when Zuul external request process, the execution logic of each type of filter. We can see from the three code try-catch
blocks, which in turn represent the pre
, route
, post
three stages of filter calls, in the catch
exception processing, we can see that they are all error
types of filter process (prior to use error
filters defined uniform exception handling also took advantage of this feature); error
after the type of filter processed, in addition from post
outside of the abnormal phase, will then be post
treated filter. For the post
case thrown exception filter in through the error
after filter processing, no other type of filter to take over the presence of the root causes of deficiencies in the program before using it is.
Recall that two kinds of exception handling methods prior to implementation, in which the very core of it, these two treatment methods in the context of exception handling request time to add a series of error.*
parameters, and these parameters where the real work is in the post
stage of SendErrorFilter
in the filter parameters will be used to organize the content back to the client. As for the post
case of phase throwing an exception by error
not calling after processing filter post
request phase, of course, these error.*
parameters will not be SendErrorFilter
the consumer output. So, if we have a custom post
filter when not properly handle the exception, it is still likely to appear in the log and no abnormal response to a request is empty question. We can modify before ThrowExceptionFilter
the filterType
modification is post
to verify the existence of this problem, pay attention to remove the try-catch
processing block, it can throw an exception.
To solve the above problems there are many, such as the most direct we can achieve error
when the filter results are returned directly to the organization will be able to achieve the effect, but such shortcomings are obvious, for information organization and error codes returned achieve it there will be multiple copies, this is very difficult for our future code maintenance work. Therefore, in order to maintain consistent exception return processing logic, we still hope will be post
an exception to be able to filter thrown SendErrorFilter
to handle.
In the foregoing, we have achieved a ErrorFilter
captured pre
, route
, post
filter thrown exception, and tissue error.*
parameters within the context of the request. Since our goal is to follow SendErrorFilter
, these error.*
parameters are still useful to us, so we can continue to use the filter to make it in post
time to throw an exception filter, continue to organize error.*
parameters, but here we can not have these error.*
parameters before being passed to SendErrorFitler
filter It is to deal with. So, we need to ErrorFilter
re-define the filter after a error
type of filter, let it come to realize SendErrorFilter
the function, but the error
filter does not need to deal with all the unusual circumstances, it is only post
an exception was thrown effective filter. According to the above ideas, we can create a class that inherits from SendErrorFilter
the filter, it can reuse run
method, and then rewrite it to the type, order, and execution conditions, to achieve multiplexing of the original logic, specifically implemented as follows:
https://www.cnblogs.com/duanxz/p/7543040.html