我已經創建了一個servlet過濾器,現在無論拋出異常,原因始終是過濾器類。 我正在使用request.exception
檢索ErrorController中的異常類。
堆棧跟蹤:
了java.lang.RuntimeException:
在my.MyController $ _closure4.doCall(MyController.groovy:68)
...
在my.MyFilter.doFilter(MyFilter .groovy作爲:38)
...
在java.lang.Thread.run(Thread.java:745)
我不能例外的真正原因:/Grails:使用servlet過濾器時的錯誤異常className
那麼爲什麼request.exception.getClassName()
返回MyFilter而不是MyController?
MyFilter:
@CompileStatic
類MyFilter實現過濾器{
UrlMappingsHolder grailsUrlMappingsHolder
MyService myService
@Override
void init(FilterConfig filterConfig) throws ServletException {
}
@Override
void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String url = ((HttpServletRequest)servletRequest).getServletPath()
def urlInfo = grailsUrlMappingsHolder.match(url).getParameters()
if (!myService.controllersToNotCheck.contains(urlInfo.controller) && !myService.sourcesExist()) {
throw new NoEnvironmentException()
}
filterChain.doFilter(servletRequest, servletResponse)
}
@Override
void destroy() {
}
}
您是否在MyController.groovy中檢查第68行? –
@VinayPrajapati問題不在位置,其中引發exeption,但在ErrorController中,所有錯誤都重定向。當我處理這個異常時,代碼** request.exception.getClassName()**總是返回「MyFilter」(而不是「MyController」,在這種情況下),並且實際拋出什麼類的異常無關緊要。 –
嗯,在異常上試試getCause()? – railsdog