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:
parent
7cd5a47fbf
commit
208152b55c
@ -139,6 +139,10 @@ public class RefineServlet extends Butterfly {
|
||||
super.service(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
public ButterflyModule getModule(String name) {
|
||||
return _modulesByName.get(name);
|
||||
}
|
||||
|
||||
protected String getCommandKey(HttpServletRequest request) {
|
||||
// A command path has this format: /command/module-name/command-name/...
|
||||
|
@ -10,6 +10,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
@ -273,6 +274,35 @@ public abstract class Command {
|
||||
e.printStackTrace(response.getWriter());
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
response.sendRedirect(url);
|
||||
|
@ -36,6 +36,7 @@ import org.apache.commons.fileupload.util.Streams;
|
||||
import org.apache.tools.bzip2.CBZip2InputStream;
|
||||
import org.apache.tools.tar.TarEntry;
|
||||
import org.apache.tools.tar.TarInputStream;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -93,10 +94,7 @@ public class CreateProjectCommand extends Command {
|
||||
|
||||
redirect(response, "/project?project=" + project.id);
|
||||
} catch (Exception e) {
|
||||
redirect(response, "/error.html?redirect=index.html&msg=" +
|
||||
ParsingUtilities.encode("Failed to import file: " + e.getLocalizedMessage())
|
||||
);
|
||||
e.printStackTrace();
|
||||
respondWithErrorPage(request, response, "Failed to import file", e);
|
||||
} finally {
|
||||
ProjectManager.singleton.setBusy(false);
|
||||
}
|
||||
|
@ -53,12 +53,10 @@ public class ImportProjectCommand extends Command {
|
||||
|
||||
redirect(response, "/project?project=" + projectID);
|
||||
} else {
|
||||
redirect(response, "/error.html?redirect=index&msg=" +
|
||||
ParsingUtilities.encode("Failed to import project")
|
||||
);
|
||||
respondWithErrorPage(request, response, "Failed to import project. Reason unknown.", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
respondWithErrorPage(request, response, "Failed to import project", e);
|
||||
} finally {
|
||||
ProjectManager.singleton.setBusy(false);
|
||||
}
|
||||
|
25
main/webapp/modules/core/error.vt
Normal file
25
main/webapp/modules/core/error.vt
Normal 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>
|
Loading…
Reference in New Issue
Block a user