fix: 500 error response when downloading non-existent trace files
This commit is contained in:
parent
b1a3bc8565
commit
1021088f5f
|
@ -552,6 +552,8 @@ group_trace_files(TraceLog, TraceFiles) ->
|
|||
empty;
|
||||
({ok, _Node, _Bin}) ->
|
||||
nonempty;
|
||||
({error, _Node, enoent}) ->
|
||||
empty;
|
||||
({error, Node, Reason}) ->
|
||||
?SLOG(error, #{
|
||||
msg => "download_trace_log_error",
|
||||
|
|
|
@ -389,7 +389,16 @@ t_download_empty_trace(_Config) ->
|
|||
),
|
||||
{error, {{_, 404, _}, _Headers, Body}} =
|
||||
request_api(get, api_path(<<"trace/", Name/binary, "/download">>), [], #{return_all => true}),
|
||||
?assertMatch(#{<<"message">> := <<"Trace is empty">>}, emqx_utils_json:decode(Body)).
|
||||
?assertMatch(#{<<"message">> := <<"Trace is empty">>}, emqx_utils_json:decode(Body)),
|
||||
File = emqx_trace:log_file(Name, Now),
|
||||
ct:pal("FileName: ~p", [File]),
|
||||
?assertEqual({ok, <<>>}, file:read_file(File)),
|
||||
?assertEqual(ok, file:delete(File)),
|
||||
%% return 404 if trace file is not found
|
||||
{error, {{_, 404, _}, _Headers, Body}} =
|
||||
request_api(get, api_path(<<"trace/", Name/binary, "/download">>), [], #{return_all => true}),
|
||||
?assertMatch(#{<<"message">> := <<"Trace is empty">>}, emqx_utils_json:decode(Body)),
|
||||
ok.
|
||||
|
||||
to_rfc3339(Second) ->
|
||||
list_to_binary(calendar:system_time_to_rfc3339(Second)).
|
||||
|
|
Loading…
Reference in New Issue