jadahl / mod_restful

RESTful interface to ejabberd
84 stars 34 forks source link

registered_users failed #1

Closed funorpain closed 13 years ago

funorpain commented 13 years ago

see below

POST /api/admin HTTP/1.1
HOST: v3.example.com
Content-Type: application/json
Content-Length: 71

{"key":"secret","command":"registered_users","args":["v3.example.com"]}
=ERROR REPORT==== 2011-02-23 13:28:06 ===
** Generic server 'mod_restful_v3.example.com' terminating 
** Last message in was {process,
                           ["admin"],
                           {request,'POST',
                               ["api","admin"],
                               [{nokey,
                                    "{\"key\":\"secret\",\"command\":\"registered_users\",\"args\":[\"v3.example.com\"]}"}],
                               undefined,undefined,"en",
                               "{\"key\":\"secret\",\"command\":\"registered_users\",\"args\":[\"v3.example.com\"]}",
                               {{127,0,0,1},49433},
                               "v3.example.com",80,http,
                               [{'Content-Length',"71"},
                                {'Content-Type',"application/json"},
                                {'Host',"v3.example.com"}]}}
** When Server state == {state,undefined,
                            [{["admin"],
                              mod_restful_admin,
                              [{key,"secret"},
                               {allowed_commands,
                                   [register,unregister,registered_users,
                                    get_roster]}]},
                             {["register"],
                              mod_restful_register,
                              [{key,"secret"}]}]}
** Reason for termination == 
** {function_clause,
       [{mod_restful_admin,format_result_json,
            [["aaa","aaaa","admin","asdf","asdfg","asdfga","fdsa","qqq",
              "qqqa","qqqq","qqqqq","z1","z2","zaz","zaz1","zaza","zzcc",
              "zzccc","zzz","zzzz"],
             {users,{list,{username,string}}}]},
        {mod_restful_admin,format_result,3},
        {mod_restful_admin,do_process,1},
        {mod_restful,handle_call,3},
        {gen_server,handle_msg,5},
        {proc_lib,init_p_do_apply,3}]}
diff --git a/src/mod_restful_admin.erl b/src/mod_restful_admin.erl
index 1b254fa..4d55f42 100644
--- a/src/mod_restful_admin.erl
+++ b/src/mod_restful_admin.erl
@@ -201,8 +201,10 @@ format_result_json(Code, {_, rescode}) ->
     Code;
 format_result_json({Code, Text}, {_, restuple}) ->
     [{Code, list_to_binary(Text)}];
-format_result_json([Es], {_, {list, ElementsF}}) ->
-    [format_result_json(E, ElementsF) || E <- Es];
+format_result_json([E], {_, {list, ElementsF}}) ->
+    [format_result_json(E, ElementsF)];
+format_result_json([E|T], {X, {list, ElementsF}}) ->
+    [format_result_json(E, ElementsF) | format_result_json(T, {X, {list, ElementsF}}) ];
 format_result_json(Tuple, {_, {tuple, ElementsF}}) ->
     TupleL = tuple_to_list(Tuple),
     % format a tuple as a list
jadahl commented 13 years ago

Thank you for the patch! I have committed it and pushed to the repository.