fix: add api auth failed code def & fix bad spelling

This commit is contained in:
DDDHuang 2022-03-24 11:31:31 +08:00
parent 5a6023676e
commit 9037b807ae
2 changed files with 11 additions and 2 deletions

View File

@ -14,6 +14,12 @@
%% limitations under the License. %% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% HTTP API Auth
-define(WRONG_USERNAME_OR_PWD, 'WRONG_USERNAME_OR_PWD').
-define(WRONG_USERNAME_OR_PWD_OR_API_KEY_OR_API_SECRET,
'WRONG_USERNAME_OR_PWD_OR_API_KEY_OR_API_SECRET'
).
%% Bad Request %% Bad Request
-define(BAD_REQUEST, 'BAD_REQUEST'). -define(BAD_REQUEST, 'BAD_REQUEST').
-define(NOT_MATCH, 'NOT_MATCH'). -define(NOT_MATCH, 'NOT_MATCH').
@ -50,6 +56,8 @@
%% All codes %% All codes
-define(ERROR_CODES, [ -define(ERROR_CODES, [
{'WRONG_USERNAME_OR_PWD', <<"Wrong username or pwd">>},
{'WRONG_USERNAME_OR_PWD_OR_API_KEY_OR_API_SECRET', <<"Wrong username & pwd or key & secret">>},
{'BAD_REQUEST', <<"Request parameters are not legal">>}, {'BAD_REQUEST', <<"Request parameters are not legal">>},
{'NOT_MATCH', <<"Conditions are not matched">>}, {'NOT_MATCH', <<"Conditions are not matched">>},
{'ALREADY_EXISTS', <<"Resource already existed">>}, {'ALREADY_EXISTS', <<"Resource already existed">>},

View File

@ -26,6 +26,7 @@
-export([authorize/1]). -export([authorize/1]).
-include_lib("emqx/include/logger.hrl"). -include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/http_api.hrl").
-define(BASE_PATH, "/api/v5"). -define(BASE_PATH, "/api/v5").
@ -166,11 +167,11 @@ authorize(Req) ->
ok; ok;
{error, <<"not_allowed">>} -> {error, <<"not_allowed">>} ->
return_unauthorized( return_unauthorized(
<<"WORNG_USERNAME_OR_PWD">>, ?WRONG_USERNAME_OR_PWD,
<<"Check username/password">>); <<"Check username/password">>);
{error, _} -> {error, _} ->
return_unauthorized( return_unauthorized(
<<"WORNG_USERNAME_OR_PWD_OR_API_KEY_OR_API_SECRET">>, ?WRONG_USERNAME_OR_PWD_OR_API_KEY_OR_API_SECRET,
<<"Check username/password or api_key/api_secret">>) <<"Check username/password or api_key/api_secret">>)
end; end;
{error, _} -> {error, _} ->