diff src/nabble/view/lib/NabbleErrorFilter.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/nabble/view/lib/NabbleErrorFilter.java	Thu Mar 21 19:15:52 2019 -0600
@@ -0,0 +1,43 @@
+package nabble.view.lib;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class NabbleErrorFilter implements Filter {
+	public static final String WORK_AROUND_ERROR_EXCEPTION = "work-around.error.exception";
+
+	public void destroy() { }
+
+	public void doFilter(ServletRequest req, ServletResponse res,
+			FilterChain chain) throws IOException, ServletException {
+		
+		try {
+			chain.doFilter(req, res);
+		} catch(Exception e) {
+			req.setAttribute(WORK_AROUND_ERROR_EXCEPTION, e);
+			
+			if(e instanceof RuntimeException) {
+				RuntimeException th = (RuntimeException)e;
+				throw th;
+			} 
+			else if(e instanceof IOException) {
+				IOException th = (IOException)e;
+				throw th;
+			} else {
+				ServletException th = (ServletException)e;
+				if( MinorServletException.isIn(th) )
+					throw new IOException(th);
+				throw th;
+			}
+		} 
+	}
+	
+	public void init(FilterConfig arg0) throws ServletException { }
+
+}