fix: return 409 in case of duplicate
This commit is contained in:
parent
5b144cd5aa
commit
2a27d2e781
|
@ -84,11 +84,16 @@ schema("/trace") ->
|
|||
200 => hoconsc:ref(trace),
|
||||
400 => emqx_dashboard_swagger:error_codes(
|
||||
[
|
||||
'ALREADY_EXISTS',
|
||||
'DUPLICATE_CONDITION',
|
||||
'INVALID_PARAMS'
|
||||
],
|
||||
<<"trace name already exists">>
|
||||
<<"invalid trace params">>
|
||||
),
|
||||
409 => emqx_dashboard_swagger:error_codes(
|
||||
[
|
||||
'ALREADY_EXISTS',
|
||||
'DUPLICATE_CONDITION'
|
||||
],
|
||||
<<"trace already exists">>
|
||||
)
|
||||
}
|
||||
},
|
||||
|
@ -392,12 +397,12 @@ trace(post, #{body := Param}) ->
|
|||
{ok, Trace0} ->
|
||||
{200, format_trace(Trace0)};
|
||||
{error, {already_existed, Name}} ->
|
||||
{400, #{
|
||||
{409, #{
|
||||
code => 'ALREADY_EXISTS',
|
||||
message => ?TO_BIN([Name, " Already Exists"])
|
||||
}};
|
||||
{error, {duplicate_condition, Name}} ->
|
||||
{400, #{
|
||||
{409, #{
|
||||
code => 'DUPLICATE_CONDITION',
|
||||
message => ?TO_BIN([Name, " Duplication Condition"])
|
||||
}};
|
||||
|
|
|
@ -149,7 +149,7 @@ t_create_failed(_Config) ->
|
|||
{ok, Create} = request_api(post, api_path("trace"), Header, [GoodName | Trace]),
|
||||
?assertMatch(#{<<"name">> := <<"test-name-0">>}, json(Create)),
|
||||
?assertMatch(
|
||||
{error, {"HTTP/1.1", 400, _}, _},
|
||||
{error, {"HTTP/1.1", 409, _}, _},
|
||||
request_api(post, api_path("trace"), Header, [GoodName | Trace])
|
||||
),
|
||||
|
||||
|
@ -171,6 +171,16 @@ t_create_failed(_Config) ->
|
|||
{error, {"HTTP/1.1", 400, _}, _},
|
||||
request_api(post, api_path("trace"), Header, [GoodName1 | Trace])
|
||||
),
|
||||
%% clear
|
||||
?assertMatch({ok, _}, request_api(delete, api_path("trace"), Header, [])),
|
||||
{ok, Create} = request_api(post, api_path("trace"), Header, [GoodName | Trace]),
|
||||
%% new name but same trace
|
||||
GoodName2 = {<<"name">>, <<"test-name-1">>},
|
||||
?assertMatch(
|
||||
{error, {"HTTP/1.1", 409, _}, _},
|
||||
request_api(post, api_path("trace"), Header, [GoodName2 | Trace])
|
||||
),
|
||||
|
||||
unload(),
|
||||
emqx_trace:clear(),
|
||||
ok.
|
||||
|
|
Loading…
Reference in New Issue