很多地方其实不是程序代码错误,
比如说上传文件大小超过 配置设定的文件大小
上传的时候就会抛出 代码错误
但是我想要的是返回错误提示信息,而不是代码错误,请那位大神给个自定义动作链处理 错误信息的例子
5 回复
@wendal 我研究一下
我自定义了 org.nutz.mvc.impl.processor.OnFailProcessor错误处理动作链,并且加入了处理,但是依然无法输出 错误信息
package org.nutz.mvc.impl.processor;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionInfo;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.NutConfig;
import static org.nutz.mvc.impl.processor.ViewProcessor.evalView;
import org.nutz.mvc.upload.UploadUnsupportedFileNameException;
/**
*
* @author zozoh(zozohtnt@gmail.com)
* @author wendal(wendal1985@gmail.com)
*
*/
public class OnFailProcessor extends ViewProcessor {
private static final Log log = Logs.get();
@Override
public void init(NutConfig config, ActionInfo ai) throws Throwable {
view = evalView(config, ai, ai.getFailView());
}
@Override
public void process(ActionContext ac) throws Throwable {
try{
System.out.println ( "xxx2x");
if (log.isWarnEnabled()) {
String uri = Mvcs.getRequestPath(ac.getRequest());
log.warn(String.format("Error@%s :", uri), ac.getError());
}
System.out.println ( "xxxx");
super.process(ac);
}catch(UploadUnsupportedFileNameException e){
e.printStackTrace ();
}
catch(Throwable e){
Throwable fillInStackTrace = e.fillInStackTrace ();
}
}
}
依然抛出错误代码
xxx2x
2016-04-28 14:03:06,123 [WARN][org.nutz.mvc.impl.processor.OnFailProcessor] - Error@/admin/file/upload :
org.nutz.mvc.upload.UploadUnsupportedFileNameException: Unsupport file name 'bj-bjmr110_�ƹ�ƻ�_2016-03-22.csv'
at org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:141)
at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:189)
at org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:65)
at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:222)
at org.nutz.mvc.upload.UploadAdaptor.adapt(UploadAdaptor.java:120)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:51)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
xxxx
2016-04-28 14:03:06,139 [DEBUG][org.nutz.mvc.impl.UrlMappingImpl] - Found mapping for [GET] path=/admin/common/unauthorized : CommonAct.unauthorized(CommonAct.java:32)
添加回复
请先登陆