Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PISTON-1085: Do not overwrite a system error message if its set when adding the error to a crossbar context #6700

Open
wants to merge 1 commit into
base: 4.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions applications/crossbar/src/cb_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1031,37 +1031,32 @@ add_system_error(Error, Props, Context) when is_list(Props) ->
JObj = kz_json:from_list(Props),
add_system_error(Error, JObj, Context);
add_system_error('bad_identifier'=Error, JObj, Context) ->
J = kz_json:set_value(<<"message">>, <<"bad identifier">>, JObj),
J = kz_json:insert_value(<<"message">>, <<"bad identifier">>, JObj),
build_system_error(404, Error, J, Context);
add_system_error('not_found', JObj, Context) ->
add_system_error('bad_identifier', JObj, Context);
add_system_error('invalid_bulk_type'=Error, JObj, Context) ->
%% TODO: JObj is expected to have a type key!!
Type = kz_json:get_value(<<"type">>, JObj),
Message = <<"bulk operations do not support documents of type ", (kz_term:to_binary(Type))/binary>>,
J = kz_json:set_value(<<"message">>, Message, JObj),
J = kz_json:insert_value(<<"message">>, Message, JObj),
build_system_error(400, Error, J, Context);
add_system_error('forbidden'=Error, JObj, Context) ->
J = kz_json:set_value(<<"message">>, <<"forbidden">>, JObj),
J = kz_json:insert_value(<<"message">>, <<"forbidden">>, JObj),
build_system_error(403, Error, J, Context);
add_system_error('timeout'=Error, JObj, Context) ->
J = kz_json:set_value(<<"message">>, <<"timeout">>, JObj),
J = kz_json:insert_value(<<"message">>, <<"timeout">>, JObj),
build_system_error(500, Error, J, Context);
add_system_error('invalid_method'=Error, JObj, Context) ->
J = kz_json:set_value(<<"message">>, <<"invalid method">>, JObj),
J = kz_json:insert_value(<<"message">>, <<"invalid method">>, JObj),
build_system_error(405, Error, J, Context);
add_system_error('bad_gateway'=Error, JObj, Context) ->
build_system_error(502, Error, JObj, Context);
add_system_error('multiple_choice'=Error, JObj, Context) ->
build_system_error(400, Error, JObj, Context);
add_system_error(Error, JObj, Context) ->
case kz_json:get_ne_value(<<"message">>, JObj) of
'undefined' ->
J = kz_json:set_value(<<"message">>, <<"unknown failure">>, JObj),
build_system_error(500, Error, J, Context);
_Else ->
build_system_error(500, Error, JObj, Context)
end.
J = kz_json:insert_value(<<"message">>, <<"unknown failure">>, JObj),
build_system_error(500, Error, J, Context).

-spec add_system_error(integer(), atom() | kz_term:ne_binary(), kz_term:ne_binary() | kz_json:object(), context()) -> context().
add_system_error(Code, Error, JObj, Context) ->
Expand Down