mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Improve error formatting in mod_http_upload
This commit is contained in:
parent
47d117c1bf
commit
881e02632b
@ -30,7 +30,6 @@
|
|||||||
|
|
||||||
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
||||||
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
|
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
|
||||||
-define(FORMAT(Error), file:format_error(Error)).
|
|
||||||
-define(URL_ENC(URL), binary_to_list(misc:url_encode(URL))).
|
-define(URL_ENC(URL), binary_to_list(misc:url_encode(URL))).
|
||||||
-define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(misc:ip_to_list(IP))).
|
-define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(misc:ip_to_list(IP))).
|
||||||
-define(STR_TO_INT(Str, B), binary_to_integer(iolist_to_binary(Str), B)).
|
-define(STR_TO_INT(Str, B), binary_to_integer(iolist_to_binary(Str), B)).
|
||||||
@ -389,8 +388,8 @@ process(_LocalPath, #request{method = 'PUT', host = Host, ip = IP,
|
|||||||
{ok, Headers, OutData} ->
|
{ok, Headers, OutData} ->
|
||||||
http_response(201, Headers ++ CustomHeaders, OutData);
|
http_response(201, Headers ++ CustomHeaders, OutData);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
?ERROR_MSG("Cannot store file ~s from ~s for ~s: ~p",
|
?INFO_MSG("Cannot store file ~s from ~s for ~s: ~s",
|
||||||
[Path, ?ADDR_TO_STR(IP), Host, ?FORMAT(Error)]),
|
[Path, ?ADDR_TO_STR(IP), Host, format_error(Error)]),
|
||||||
http_response(500)
|
http_response(500)
|
||||||
end;
|
end;
|
||||||
{error, size_mismatch} ->
|
{error, size_mismatch} ->
|
||||||
@ -443,7 +442,7 @@ process(_LocalPath, #request{method = Method, host = Host, ip = IP} = Request)
|
|||||||
http_response(404);
|
http_response(404);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
?INFO_MSG("Cannot serve ~s to ~s: ~s",
|
?INFO_MSG("Cannot serve ~s to ~s: ~s",
|
||||||
[Path, ?ADDR_TO_STR(IP), ?FORMAT(Error)]),
|
[Path, ?ADDR_TO_STR(IP), format_error(Error)]),
|
||||||
http_response(500)
|
http_response(500)
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
@ -827,6 +826,20 @@ code_to_message(413) -> <<"File size doesn't match requested size.">>;
|
|||||||
code_to_message(500) -> <<"Internal server error.">>;
|
code_to_message(500) -> <<"Internal server error.">>;
|
||||||
code_to_message(_Code) -> <<"">>.
|
code_to_message(_Code) -> <<"">>.
|
||||||
|
|
||||||
|
-spec format_error(atom()) -> string().
|
||||||
|
format_error(Reason) ->
|
||||||
|
case file:format_error(Reason) of
|
||||||
|
"unknown POSIX error" ->
|
||||||
|
case inet:format_error(Reason) of
|
||||||
|
"unknown POSIX error" ->
|
||||||
|
atom_to_list(Reason);
|
||||||
|
Txt ->
|
||||||
|
Txt
|
||||||
|
end;
|
||||||
|
Txt ->
|
||||||
|
Txt
|
||||||
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Image manipulation stuff.
|
%% Image manipulation stuff.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
@ -848,7 +861,7 @@ identify(Path) ->
|
|||||||
end
|
end
|
||||||
catch _:{badmatch, {error, Reason}} ->
|
catch _:{badmatch, {error, Reason}} ->
|
||||||
?DEBUG("Failed to read file ~s: ~s",
|
?DEBUG("Failed to read file ~s: ~s",
|
||||||
[Path, file:format_error(Reason)]),
|
[Path, format_error(Reason)]),
|
||||||
pass
|
pass
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -878,7 +891,7 @@ convert(Path, #media_info{type = T, width = W, height = H} = Info) ->
|
|||||||
{ok, OutPath, OutInfo};
|
{ok, OutPath, OutInfo};
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
?ERROR_MSG("Failed to write to ~s: ~s",
|
?ERROR_MSG("Failed to write to ~s: ~s",
|
||||||
[OutPath, file:format_error(Why)]),
|
[OutPath, format_error(Why)]),
|
||||||
pass
|
pass
|
||||||
end;
|
end;
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
@ -888,7 +901,7 @@ convert(Path, #media_info{type = T, width = W, height = H} = Info) ->
|
|||||||
end;
|
end;
|
||||||
{error, Why} ->
|
{error, Why} ->
|
||||||
?ERROR_MSG("Failed to read file ~s: ~s",
|
?ERROR_MSG("Failed to read file ~s: ~s",
|
||||||
[Path, file:format_error(Why)]),
|
[Path, format_error(Why)]),
|
||||||
pass
|
pass
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
@ -917,8 +930,8 @@ remove_user(User, Server) ->
|
|||||||
{error, enoent} ->
|
{error, enoent} ->
|
||||||
?DEBUG("Found no HTTP upload directory of ~s@~s", [User, Server]);
|
?DEBUG("Found no HTTP upload directory of ~s@~s", [User, Server]);
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~p",
|
?ERROR_MSG("Cannot remove HTTP upload directory of ~s@~s: ~s",
|
||||||
[User, Server, ?FORMAT(Error)])
|
[User, Server, format_error(Error)])
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user