fix: return 404 in case node is not found
This commit is contained in:
parent
9ecf154a71
commit
e78c2c2869
|
@ -51,7 +51,6 @@
|
||||||
|
|
||||||
-define(TO_BIN(_B_), iolist_to_binary(_B_)).
|
-define(TO_BIN(_B_), iolist_to_binary(_B_)).
|
||||||
-define(NOT_FOUND(N), {404, #{code => 'NOT_FOUND', message => ?TO_BIN([N, " NOT FOUND"])}}).
|
-define(NOT_FOUND(N), {404, #{code => 'NOT_FOUND', message => ?TO_BIN([N, " NOT FOUND"])}}).
|
||||||
-define(BAD_REQUEST(C, M), {400, #{code => C, message => ?TO_BIN(M)}}).
|
|
||||||
-define(SERVICE_UNAVAILABLE(C, M), {503, #{code => C, message => ?TO_BIN(M)}}).
|
-define(SERVICE_UNAVAILABLE(C, M), {503, #{code => C, message => ?TO_BIN(M)}}).
|
||||||
-define(TAGS, [<<"Trace">>]).
|
-define(TAGS, [<<"Trace">>]).
|
||||||
|
|
||||||
|
@ -151,8 +150,9 @@ schema("/trace/:name/download") ->
|
||||||
#{schema => #{type => "string", format => "binary"}}
|
#{schema => #{type => "string", format => "binary"}}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
400 => emqx_dashboard_swagger:error_codes(['NODE_ERROR'], <<"Node Not Found">>),
|
404 => emqx_dashboard_swagger:error_codes(
|
||||||
404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"Trace Name Not Found">>)
|
['NOT_FOUND', 'NODE_ERROR'], <<"Trace Name or Node Not Found">>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -188,10 +188,10 @@ schema("/trace/:name/log") ->
|
||||||
{meta, fields(bytes) ++ fields(position)}
|
{meta, fields(bytes) ++ fields(position)}
|
||||||
],
|
],
|
||||||
400 => emqx_dashboard_swagger:error_codes(
|
400 => emqx_dashboard_swagger:error_codes(
|
||||||
['BAD_REQUEST', 'NODE_ERROR'], <<"Bad input parameter">>
|
['BAD_REQUEST'], <<"Bad input parameter">>
|
||||||
),
|
),
|
||||||
404 => emqx_dashboard_swagger:error_codes(
|
404 => emqx_dashboard_swagger:error_codes(
|
||||||
['NOT_FOUND'], <<"Trace Name Not Found">>
|
['NOT_FOUND', 'NODE_ERROR'], <<"Trace Name or Node Not Found">>
|
||||||
),
|
),
|
||||||
503 => emqx_dashboard_swagger:error_codes(
|
503 => emqx_dashboard_swagger:error_codes(
|
||||||
['SERVICE_UNAVAILABLE'], <<"Requested chunk size too big">>
|
['SERVICE_UNAVAILABLE'], <<"Requested chunk size too big">>
|
||||||
|
@ -509,7 +509,7 @@ download_trace_log(get, #{bindings := #{name := Name}, query_string := Query}) -
|
||||||
},
|
},
|
||||||
{200, Headers, {file_binary, ZipName, Binary}};
|
{200, Headers, {file_binary, ZipName, Binary}};
|
||||||
{error, not_found} ->
|
{error, not_found} ->
|
||||||
?BAD_REQUEST('NODE_ERROR', <<"Node not found">>)
|
?NOT_FOUND(<<"Node">>)
|
||||||
end;
|
end;
|
||||||
{error, not_found} ->
|
{error, not_found} ->
|
||||||
?NOT_FOUND(Name)
|
?NOT_FOUND(Name)
|
||||||
|
@ -602,10 +602,10 @@ stream_log_file(get, #{bindings := #{name := Name}, query_string := Query}) ->
|
||||||
}),
|
}),
|
||||||
?SERVICE_UNAVAILABLE('SERVICE_UNAVAILABLE', <<"Requested chunk size too big">>);
|
?SERVICE_UNAVAILABLE('SERVICE_UNAVAILABLE', <<"Requested chunk size too big">>);
|
||||||
{badrpc, nodedown} ->
|
{badrpc, nodedown} ->
|
||||||
?BAD_REQUEST('NODE_ERROR', <<"Node not found">>)
|
?NOT_FOUND(<<"Node">>)
|
||||||
end;
|
end;
|
||||||
{error, not_found} ->
|
{error, not_found} ->
|
||||||
?BAD_REQUEST('NODE_ERROR', <<"Node not found">>)
|
?NOT_FOUND(<<"Node">>)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_trace_size() -> #{{node(), file:name_all()} => non_neg_integer()}.
|
-spec get_trace_size() -> #{{node(), file:name_all()} => non_neg_integer()}.
|
||||||
|
|
|
@ -223,12 +223,12 @@ t_log_file(_Config) ->
|
||||||
]},
|
]},
|
||||||
zip:table(Binary2)
|
zip:table(Binary2)
|
||||||
),
|
),
|
||||||
{error, {_, 400, _}} =
|
{error, {_, 404, _}} =
|
||||||
request_api(
|
request_api(
|
||||||
get,
|
get,
|
||||||
api_path("trace/test_client_id/download?node=unknonwn_node")
|
api_path("trace/test_client_id/download?node=unknown_node")
|
||||||
),
|
),
|
||||||
{error, {_, 400, _}} =
|
{error, {_, 404, _}} =
|
||||||
request_api(
|
request_api(
|
||||||
get,
|
get,
|
||||||
% known atom but unknown node
|
% known atom but unknown node
|
||||||
|
@ -303,12 +303,12 @@ t_stream_log(_Config) ->
|
||||||
meck:expect(file, read, 2, {error, enomem}),
|
meck:expect(file, read, 2, {error, enomem}),
|
||||||
{error, {_, 503, _}} = request_api(get, Path),
|
{error, {_, 503, _}} = request_api(get, Path),
|
||||||
meck:unload(file),
|
meck:unload(file),
|
||||||
{error, {_, 400, _}} =
|
{error, {_, 404, _}} =
|
||||||
request_api(
|
request_api(
|
||||||
get,
|
get,
|
||||||
api_path("trace/test_stream_log/log?node=unknonwn_node")
|
api_path("trace/test_stream_log/log?node=unknown_node")
|
||||||
),
|
),
|
||||||
{error, {_, 400, _}} =
|
{error, {_, 404, _}} =
|
||||||
request_api(
|
request_api(
|
||||||
get,
|
get,
|
||||||
% known atom but not a node
|
% known atom but not a node
|
||||||
|
|
Loading…
Reference in New Issue