anchor.diff:          {error, Reason} -> {error, Reason};
           {ok, List} ->
               case List of
  -                [] -> {error, TokenName ++ " not valid"};
  -                JSON when is_tuple(JSON) ->
  -                    Source = lib_json:get_field(JSON, "hits.hits"),
  -                    {ok, Source};
  -                    % Result = lib_json:get_field(Source, "_source"),
  -                    % Tok = binary_to_list(lib_json:get_field(Result, TokenName)),
  -                    % case TokenValue == Tok of
  -                    %     true  -> {ok, Tok};
  -                    %     false -> {error, "Not possible to perform the request. " ++ TokenName ++ " mismatches"}
  -                    % end;
  +                [] -> {error, "No users found by the given token"};
  +                Li when is_tuple(Li) ->
  +                    JSONList = lib_json:get_field(Li, "hits.hits"),
  +                    Lambda = fun(JSON) ->
  +                        Source = lib_json:get_field(JSON, "_source"),
  +                        Tok = binary_to_list(lib_json:get_field(Source, TokenName)),
  +                        case TokenValue == Tok of
  +                            true  -> throw({ok, Tok});
  +                            false -> false
  +                        end
  +                    end,
  +
  +                    try lists:map(Lambda, JSONList)
  +                    catch
  +                        throw:X -> X;
  +                        _:_ -> {error, "Not possible to perform the request. " ++ TokenName ++ " mismatches"}
  +                    end;
  +
  +                    % {error, "Not possible to perform the request. " ++ TokenName ++ " mismatches"};
  +
                   _ -> {error, TokenName ++ " not valid"}
               end
       end.
  +
   
   -spec get_user_model(ReqData::tuple(), State::string()) -> {list(), tuple(), string()}.
   get_user_model(ReqData, State) ->
  
positive.code:             case api_help:is_auth_redirect(ReqData) of
                  true  -> process_auth_redirect(ReqData, State);
                  false ->
                      case analyse_token(ReqData, "refresh_token") of
                          % {ok, RefTok} ->
                          {ok, _} ->
                              case api_help:is_search(ReqData) of
  
negative.code: %% @end
  -spec delete_resource(ReqData::tuple(), State::string()) -> {string(), tuple(), string()}.
  delete_resource(ReqData, State) ->
      case analyse_token("access_token", ReqData) of
          {error, Msg} -> {{halt, 403}, wrq:set_resp_body(Msg, ReqData), State};
          {ok, Token} ->
              % {true, wrq:set_resp_body(Token, ReqData), State}
              Id = id_from_path(ReqData),
              case delete_streams_with_user_id(Id) of
                  {error, {Code, Body}} ->
                      ErrorString = api_help:generate_error(Body, Code),
                      {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
                  {ok} ->
                      case erlastic_search:delete_doc(?INDEX,"user", Id) of
                          {error, {Code, Body}} ->
                              ErrorString = api_help:generate_error(Body, Code),
                              {{halt, Code}, wrq:set_resp_body(ErrorString, ReqData), State};
                          {ok,List} ->
                              {true,wrq:set_resp_body(lib_json:encode(List),ReqData),State}
                      end
              end
      end.
  
  