Added .vt template for reporting errors with stacktraces.

Fixed Issue 155: Blank browser shown when non-GZIP format is detected during import

git-svn-id: http://google-refine.googlecode.com/svn/trunk@1469 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-10-13 04:51:01 +00:00
parent 7cd5a47fbf
commit 208152b55c
5 changed files with 63 additions and 8 deletions

View File

@ -140,6 +140,10 @@ public class RefineServlet extends Butterfly {
} }
} }
public ButterflyModule getModule(String name) {
return _modulesByName.get(name);
}
protected String getCommandKey(HttpServletRequest request) { protected String getCommandKey(HttpServletRequest request) {
// A command path has this format: /command/module-name/command-name/... // A command path has this format: /command/module-name/command-name/...

View File

@ -10,6 +10,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.velocity.VelocityContext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
@ -274,6 +275,35 @@ public abstract class Command {
} }
} }
protected void respondWithErrorPage(
HttpServletRequest request,
HttpServletResponse response,
String message,
Exception e
) {
VelocityContext context = new VelocityContext();
context.put("message", message);
if (e != null) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
context.put("stack", writer.toString());
} else {
context.put("stack", "");
}
try {
servlet.getModule("core").sendTextFromTemplate(
request, response, context, "error.vt", "UTF-8", "text/html", true);
} catch (Exception e1) {
e1.printStackTrace();
}
}
static protected void redirect(HttpServletResponse response, String url) throws IOException { static protected void redirect(HttpServletResponse response, String url) throws IOException {
response.sendRedirect(url); response.sendRedirect(url);
} }

View File

@ -36,6 +36,7 @@ import org.apache.commons.fileupload.util.Streams;
import org.apache.tools.bzip2.CBZip2InputStream; import org.apache.tools.bzip2.CBZip2InputStream;
import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream; import org.apache.tools.tar.TarInputStream;
import org.apache.velocity.VelocityContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -93,10 +94,7 @@ public class CreateProjectCommand extends Command {
redirect(response, "/project?project=" + project.id); redirect(response, "/project?project=" + project.id);
} catch (Exception e) { } catch (Exception e) {
redirect(response, "/error.html?redirect=index.html&msg=" + respondWithErrorPage(request, response, "Failed to import file", e);
ParsingUtilities.encode("Failed to import file: " + e.getLocalizedMessage())
);
e.printStackTrace();
} finally { } finally {
ProjectManager.singleton.setBusy(false); ProjectManager.singleton.setBusy(false);
} }

View File

@ -53,12 +53,10 @@ public class ImportProjectCommand extends Command {
redirect(response, "/project?project=" + projectID); redirect(response, "/project?project=" + projectID);
} else { } else {
redirect(response, "/error.html?redirect=index&msg=" + respondWithErrorPage(request, response, "Failed to import project. Reason unknown.", null);
ParsingUtilities.encode("Failed to import project")
);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); respondWithErrorPage(request, response, "Failed to import project", e);
} finally { } finally {
ProjectManager.singleton.setBusy(false); ProjectManager.singleton.setBusy(false);
} }

View File

@ -0,0 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Error - Google Refine</title>
<link rel="icon" type="image/png" href="/images/favicon.png">
<link rel="stylesheet" href="/styles/common.less" />
<link rel="stylesheet" href="/styles/error.less" />
</head>
<body>
<div id="header">
<a id="app-home-button" href="/"><img alt="Google Refine" src="/images/google-refine-home-button.png" /></a>
<div id="path"><span class="app-path-section">Error</span></div>
</div>
<div id="body">
<h1>Oops, something went wrong!</h1>
<p id="message">$message</p>
<pre>$stack</pre>
</div>
</body>
</html>