Fetch request to Riak returns 204 No Content

Михаил Яшков mike25 at ya.ru
Mon Oct 7 12:40:43 EDT 2013


Hello.
I have a little problem with Riak. I have wrote Riak-client script via Erlang. My code here:

---------------------- Code ----------------------
%% @doc Method to get object by bucket and key
get_object(Bucket, Key)->
	do_get_request(lists:concat(["/buckets/",binary_to_list(Bucket),"/keys/",binary_to_list(Key)])).


%% @doc Make GET request by request url. Response returns.
do_get_request(RequestString)->
	do_request(get, RequestString).


%% @doc Make request by method and request url without body value
do_request(Method, RequestString)->
	inets:start(temporary),
	URL = lists:concat([shared_config:get_riak_destination(), RequestString]),
        % shared_config:get_riak_destination() returns http-path to Riak.
	Resp = httpc:request(Method, {URL, []}, [], []),
	process_response(Resp).


%% @doc Method that processes response
process_response(Resp)->
	case Resp of 
		{ok, {{Version, ResponseCode, ReasonPhrase}, Headers, Body}}->
			case ResponseCode of 
				200->%ok
					{ok, Body};
				201->%created response (when riak generates key)
					{ok, Body};
				204->%if key has no content
					{ok, nocontent};
				300->%multiple content
					{error, Body};
				400->%when request parameters are invalid
					{error, badrequest};
				404->
					{error, notfound};
				412->%if one of the conditional request headers failed to match
					{error, precondition_failed};
				_->
					{error, "Unknown error: "++ResponseCode}
			end;
		{error, ErrorMsg} ->
			{error, ErrorMsg}
	end.
----------------- End of code -----------------
This code properly worked till today. But today function get_object(Bucket, Key) returns {ok, nocontent}. Response code was 204, I saw it in logs. Can anyone tell me about this behavior of Riak? This problem fixed by restarting Riak. 




More information about the riak-users mailing list