Commits

Anonymous committed 559437a

honor resp body if set, even when rendering error

Comments (0)

Files changed (1)

src/webmachine_error_handler.erl

 
 -export([render_error/3]).
 
-render_error(404, Req, _Reason) ->
+render_error(Code, Req, Reason) ->
+    case Req:has_response_body() of
+        true -> Req:response_body();
+        false -> render_error_body(Code, Req, Reason)
+    end.
+
+render_error_body(404, Req, _Reason) ->
     Req:add_response_header("Content-Type", "text/html"),
     <<"<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>Not Found</H1>The requested document was not found on this server.<P><HR><ADDRESS>mochiweb+webmachine web server</ADDRESS></BODY></HTML>">>;
 
-render_error(500, Req, Reason) ->
+render_error_body(500, Req, Reason) ->
     Req:add_response_header("Content-Type", "text/html"),
     error_logger:error_msg("webmachine error: path=~p~n~p~n", [Req:path(), Reason]),
     STString = io_lib:format("~p", [Reason]),
     ErrorIOList = [ErrorStart,STString,ErrorEnd],
     erlang:iolist_to_binary(ErrorIOList);
 
-render_error(501, Req, _Reason) ->
+render_error_body(501, Req, _Reason) ->
     Req:add_response_header("Content-Type", "text/html"),
     error_logger:error_msg("Webmachine does not support method ~p~n",
                            [Req:method()]),
                              [Req:method()]),
     erlang:iolist_to_binary(ErrorStr);
 
-render_error(503, Req, _Reason) ->
+render_error_body(503, Req, _Reason) ->
     Req:add_response_header("Content-Type", "text/html"),
     error_logger:error_msg("Webmachine cannot fulfill"
                            "the request at this time"),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.