2011-12-06 47 views
0

我正在嘗試更新我的riak數據庫中的客戶,並且我收到以下錯誤消息: 我不知道是什麼原因導致此錯誤,以及此錯誤消息的含義。無法用erlang更新客戶

而且我用的模塊:

allowed_methods(Request, State) -> 
    {['PUT'], Request, State}. 

content_types_accepted(Request, State) -> 
    {[{"application/json",to_json}], Request, State}. 

錯誤

webmachine error: path="/customer/cus/update" {error, {error,undef, [{customer_update,to_json, [{wm_reqdata,'PUT',http, {1,1}, "127.0.0.1", {wm_reqstate,#Port<0.6513>, {dict,4,16,16,8,80,48, {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}, {{[],[],[], [[mediaparams,{"charset","UTF-8"}]], [], [[resource_module|customer_update], ['content-type',116,101,120,116,47,104,116,109, 108]], [], [['content-encoding',105,100,101,110,116,105,116, 121]], [],[],[],[],[],[],[],[]}}}, undefined,"127.0.0.1",'REQDATA',undefined,undefined, {wm_log_data,undefined, {1322,989559,450145}, 'PUT', {6, {"content-length", {'Content-Length',"121"}, {"connection",{'Connection',"Keep-Alive"},nil,nil}, {"content-type", {'Content-Type', "application/json; charset=UTF-8"}, nil, {"host", {'Host',"localhost:8000"}, {"expect",{"Expect","100-Continue"},nil,nil}, {"user-agent", {'User-Agent', "Apache-HttpClient/4.0.1 (java 1.5)"}, nil,nil}}}}}, "127.0.0.1","/updatecustomer", {1,1}, 404,0,undefined,undefined,undefined}}, [],"/customer/cus/update","//customer/cus/update", {dict,0,16,16,8,80,48, {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}, {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}, [],".",500,1073741824,67108864,[],[], {6, {"content-length", {'Content-Length',"121"}, {"connection",{'Connection',"Keep-Alive"},nil,nil}, {"content-type", {'Content-Type',"application/json; charset=UTF-8"}, nil, {"host", {'Host',"localhost:8000"}, {"expect",{"Expect","100-Continue"},nil,nil}, {"user-agent", {'User-Agent',"Apache-HttpClient/4.0.1 (java 1.5)"}, nil,nil}}}}}, not_fetched_yet,false, {1,{"content-type",{"Content-Type","text/html"},nil,nil}}, <<>>, ["localhost"], 8000,[]}, undefined]}, {webmachine_resource,resource_call,3}, {webmachine_resource,do,3}, {webmachine_decision_core,resource_call,1}, {webmachine_decision_core,accept_helper,0}, {webmachine_decision_core,decision,1}, {webmachine_decision_core,handle_request,2}, {webmachine_mochiweb,loop,1}]}}

回答

4

你應該定義to_json/2功能。

例如:

to_json(RD, Result) -> 
    {mochijson:encode(Result), RD, Result}. 
+0

我在另一個模塊中定義to_json。 – user1067665

+0

+1。並閱讀一些關於webmachine的文檔,我認爲這將有助於進一步 – danechkin

0

不幸的是我缺乏美譽度伊利亞的回答進行評論。

TLDR:以您定義它

再回應模塊的名稱前綴to_json

I'm defining to_json in another module

看着你content_types_accepted/2呼叫時,您沒有指定to_json駐留在哪個模塊,因此出現undef錯誤。 Erlang函數調用始終是MFA - > module:function(arguments),如果函數位於同一個模塊中,則只能省略該模塊。

又見documentation on Erlang packages

0

理解這個錯誤的關鍵是部分:

{error, {error,undef, [{customer_update,to_json, ...

哪些報告的undef錯誤。這類錯誤的描述:

http://www.erlang.org/doc/reference_manual/errors.html#id81244

而且你可以看到undef意味着我們有一個未定義的功能。錯誤是由於電話customer_update:to_json(..),然後不存在。這是你在這裏遇到的問題。