Skip to content

Commit

Permalink
Merge pull request #63 from inaka/ferigis.62.replace_response_codes
Browse files Browse the repository at this point in the history
[#62] replacing 409 by 422
  • Loading branch information
amilkr authored Feb 15, 2017
2 parents bf00861 + eba9460 commit 30ca996
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ For **Sumo Rest** to provide urls to the callers, we need to specify the locatio
location(Element, Path) -> iolist_to_binary([Path, "/", key(Element)]).
```
To let **Sumo Rest** avoid duplicate keys (and return `409 Conflict` in that case), we provide the optional callback `duplication_conditions/1`:
To let **Sumo Rest** avoid duplicate keys (and return `422 Conflict` in that case), we provide the optional callback `duplication_conditions/1`:
```erlang
-spec duplication_conditions(element()) -> sumo_rest_doc:duplication_conditions().
duplication_conditions(Element) -> [{key, '==', key(Element)}].
Expand Down Expand Up @@ -370,7 +370,7 @@ handle_post(Req, State) ->
catch
_:conflict ->
{ok, Req3} =
cowboy_req:reply(409, [], sr_json:error(<<"Duplicated entity">>), Req),
cowboy_req:reply(422, [], sr_json:error(<<"Duplicated entity">>), Req),
{halt, Req3, State};
_:badjson ->
Req3 =
Expand Down
2 changes: 1 addition & 1 deletion src/sr_entities_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ handle_post(Req, State) ->
catch
_:conflict ->
{ok, Req3} =
cowboy_req:reply(409, [], sr_json:error(<<"Duplicated entity">>), Req),
cowboy_req:reply(422, [], sr_json:error(<<"Duplicated entity">>), Req),
{halt, Req3, State};
_:badjson ->
Req3 =
Expand Down
2 changes: 1 addition & 1 deletion src/sumo_rest_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
-callback from_json(json()) -> {ok, entity()} | {error, reason()}.
-callback update(entity(), json()) -> {ok, entity()} | {error, reason()}.
-callback location(entity(), path()) -> iodata().
%% it's only needed if dups should raise 409 conflict
%% it's only needed if dups should raise 422 conflict
-callback duplication_conditions(entity()) -> duplication_conditions().
%% it's only needed if ids are not coming in PUT jsons
-callback from_json(binary(), json()) -> {ok, entity()} | {error, reason()}.
Expand Down
4 changes: 2 additions & 2 deletions test/sr_elements_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ success_scenario(_Config) ->
[Element1] = sr_json:decode(BodyB),

ct:comment("Element 1 is modified"),
#{status_code := 409, body := Body01} =
#{status_code := 422, body := Body01} =
sr_test_utils:api_call(
put, "/elements", #{<<"content-type">> => <<"application/json">>},
#{ key => 1
Expand Down Expand Up @@ -176,7 +176,7 @@ duplicated_key(_Config) ->
sr_test_utils:api_call(post, "/elements", Headers, Body),

ct:comment("Element 1 can't be created again"),
#{status_code := 409} =
#{status_code := 422} =
sr_test_utils:api_call(post, "/elements", Headers, Body),

{comment, ""}.
Expand Down
2 changes: 1 addition & 1 deletion test/sr_test/sr_sessions_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ handle_post(Req, #{opts := Opts} = State) ->
catch
_:conflict ->
{ok, Req3} =
cowboy_req:reply(409, [], sr_json:error(<<"Duplicated entity">>), Req),
cowboy_req:reply(422, [], sr_json:error(<<"Duplicated entity">>), Req),
{halt, Req3, State};
_:badjson ->
Req3 =
Expand Down

0 comments on commit 30ca996

Please # to comment.