我正在尝试更新我的riak数据库中的客户,我收到以下错误消息: 我不知道导致此错误的原因以及此错误消息的含义。
我使用的模块是:
allowed_methods(Request, State) ->
{['PUT'], Request, State}.
content_types_accepted(Request, State) ->
{[{"application/json",to_json}], Request, State}.
错误
webmachine错误: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]], [],[],[],[],[],[],[],[]}}}, 未定义, “127.0.0.1”, 'REQDATA',不确定的,不确定的, {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”, { '主机', “本地主机: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,不确定的,不确定的,不确定}}, [] “/客户/ CUS /更新”, “//客户/ CUS /更新”, {字典,0,16,16,8,80,48, {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}, {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]} }}, [],“。”,500,1073741824,67108864,[],[],{6,{“content-length”, { '内容长度', “121”}, {“connection”,{'Connection',“Keep-Alive”},nil,nil},{“content-type”, {'Content-Type',“application / json; charset = UTF-8”},nil,{“host”, { '主机', “本地主机:8000”}, {“expect”,{“Expect”,“100-Continue”},nil,nil},{“user-agent”, {'User-Agent',“Apache-HttpClient / 4.0.1(java 1.5)”},nil,nil}}}}}, not_fetched_yet,假的, {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,决策,1}, {webmachine_decision_core,handle_request,2}, {webmachine_mochiweb,循环,1}]}}
答案 0 :(得分:4)
你应该定义to_json / 2函数。
例如:
to_json(RD, Result) ->
{mochijson:encode(Result), RD, Result}.
答案 1 :(得分:0)
不幸的是,Ilya对答案的评论缺乏声誉。
TLDR :前缀to_json
,其中包含您定义模块的名称
更长的答案:
我在另一个模块中定义了to_json
查看content_types_accepted/2
来电,您没有指定to_json
所在的模块,因此undef
错误。 Erlang函数调用始终是MFA - > module:function(arguments),如果函数在同一模块中,则只能省略模块。
答案 2 :(得分:0)
理解这个错误的关键是部分:
{error, {error,undef, [{customer_update,to_json, ...
报告undef
错误。这些错误描述于:
http://www.erlang.org/doc/reference_manual/errors.html#id81244
你可以看到undef
意味着我们有一个未定义的函数。该错误是由于呼叫customer_update:to_json(..)
导致的,然后该呼叫不存在。这就是你在这里遇到的问题。