Merge pull request #11757 from zhongwencool/trace-api-return-500

fix: 500 error response when downloading non-existent trace files
This commit is contained in:
JianBo He 2023-10-16 13:40:18 +08:00 committed by GitHub
commit 16cc816bd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -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",

View File

@ -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)).

View File

@ -0,0 +1 @@
Fixed 500 error response when downloading non-existent trace files, now returns 404.