0

我正在尝试更新我的 riak 数据库中的客户,我收到以下错误消息:而且我不知道是什么导致了这个错误以及这个错误消息的含义。

我使用的模块是:

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

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

错误

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}]}} 内容类型", {'内容类型',"应用程序/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}]}} 内容类型", {'内容类型',"应用程序/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

3 回答 3

4

您应该定义 to_json/2 函数。

例如:

to_json(RD, Result) ->
    {mochijson:encode(Result), RD, Result}.
于 2011-12-07T00:10:54.827 回答
0

不幸的是,我缺乏对 Ilya 的回答发表评论的声誉。

TLDR :to_json以您定义它的模块名称为前缀

更长的答案:

我在另一个模块中定义 to_json

查看您的content_types_accepted/2电话,您没有指定to_json驻留在哪个模块中,因此出现了undef错误。Erlang 函数调用总是 MFA -> module:function(arguments),如果函数在同一个模块中,你只能省略模块。

另请参阅有关 Erlang 包的文档

于 2012-01-07T11:14:25.813 回答
0

理解这个错误的关键是这部分:

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

哪个报告undef错误。这些类型的错误在以下位置进行了描述:

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

你可以看到这undef意味着我们有一个未定义的函数。该错误是由于customer_update:to_json(..)当时不存在的调用造成的。这就是你在这里遇到的问题。

于 2012-01-07T12:35:43.847 回答