diff --git a/framework/src/play/mvc/results/Error.java b/framework/src/play/mvc/results/Error.java index 45bdec4e6a..2d77493b7a 100644 --- a/framework/src/play/mvc/results/Error.java +++ b/framework/src/play/mvc/results/Error.java @@ -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; @@ -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 binding = Scope.RenderArgs.current().data; binding.put("exception", this); binding.put("result", this); @@ -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) { diff --git a/framework/src/play/mvc/results/Forbidden.java b/framework/src/play/mvc/results/Forbidden.java index d846945f6f..95dfae1921 100644 --- a/framework/src/play/mvc/results/Forbidden.java +++ b/framework/src/play/mvc/results/Forbidden.java @@ -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) { diff --git a/framework/src/play/mvc/results/NotFound.java b/framework/src/play/mvc/results/NotFound.java index 64288c7c3f..36a1d59d1d 100644 --- a/framework/src/play/mvc/results/NotFound.java +++ b/framework/src/play/mvc/results/NotFound.java @@ -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; @@ -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) {