Skip to content

Commit

Permalink
[#320] Error results should never throw exceptions!
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebort committed Oct 21, 2010
1 parent 32105a1 commit a87649b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 8 additions & 3 deletions framework/src/play/mvc/results/Error.java
Expand Up @@ -3,6 +3,7 @@
import java.util.Map;

import play.Play;
import play.exceptions.TemplateNotFoundException;
import play.exceptions.UnexpectedException;
import play.libs.MimeTypes;
import play.mvc.Http;
Expand Down Expand Up @@ -31,10 +32,10 @@ public Error(int status, String reason) {
public void apply(Request request, Response response) {
response.status = status;
String format = request.format;
if(request.isAjax() && "html".equals(format)) {
if (request.isAjax() && "html".equals(format)) {
format = "txt";
}
response.contentType = MimeTypes.getContentType("xx."+format);
response.contentType = MimeTypes.getContentType("xx." + format);
Map<String, Object> binding = Scope.RenderArgs.current().data;
binding.put("exception", this);
binding.put("result", this);
Expand All @@ -43,7 +44,11 @@ public void apply(Request request, Response response) {
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
String errorHtml = TemplateLoader.load("errors/" + this.status + "."+format).render(binding);
String errorHtml = getMessage();
try {
errorHtml = TemplateLoader.load("errors/" + this.status + "." + (format == null ? "html" : format)).render(binding);
} catch (Exception e) {
}
try {
response.out.write(errorHtml.getBytes("utf-8"));
} catch (Exception e) {
Expand Down
6 changes: 5 additions & 1 deletion framework/src/play/mvc/results/Forbidden.java
Expand Up @@ -34,7 +34,11 @@ public void apply(Request request, Response response) {
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
String errorHtml = TemplateLoader.load("errors/403."+format).render(binding);
String errorHtml = getMessage();
try {
errorHtml = TemplateLoader.load("errors/403."+(format == null ? "html" : format)).render(binding);
} catch(Exception e) {
}
try {
response.out.write(errorHtml.getBytes("utf-8"));
} catch (Exception e) {
Expand Down
7 changes: 6 additions & 1 deletion framework/src/play/mvc/results/NotFound.java
Expand Up @@ -3,6 +3,7 @@
import java.util.Map;

import play.Play;
import play.exceptions.TemplateNotFoundException;
import play.exceptions.UnexpectedException;
import play.libs.MimeTypes;
import play.mvc.Http;
Expand Down Expand Up @@ -45,7 +46,11 @@ public void apply(Request request, Response response) {
binding.put("flash", Scope.Flash.current());
binding.put("params", Scope.Params.current());
binding.put("play", new Play());
String errorHtml = TemplateLoader.load("errors/404."+format).render(binding);
String errorHtml = "Not found";
try {
errorHtml = TemplateLoader.load("errors/404." + (format == null ? "html" : format)).render(binding);
} catch(Exception e) {
}
try {
response.out.write(errorHtml.getBytes("utf-8"));
} catch (Exception e) {
Expand Down

0 comments on commit a87649b

Please sign in to comment.