2014-02-05 4 views
1

내 erlang 서버가 어떤 이유로 든 요청할 때마다 case_clause 오류를 생성합니다. 여기 내 코드 :
keychain_no_auth_handler.erl성공적인 응답 후 case_clause 오류 [카우보이 휴식]

-module(keychain_no_auth_handler). 
-export(
    [ init/3, 
    content_types_accepted/2, 
    terminate/3, 
    allowed_methods/2, 
    handle_request/2 
    ]). 

-export([is_registered/1]). 

init(_Transport, _Req, []) -> {upgrade, protocol, cowboy_rest}. 

terminate(_Reason, _Req, _State) -> ok. 

allowed_methods(Req, State) -> {[<<"POST">>], Req, State}. 

content_types_accepted(Req, State) -> {[{<<"application/json">>, handle_request}], Req, State}. 

handle_request(Req, State) -> 
    {Action, Req2} = cowboy_req:binding(action, Req), 

    {Reply, Req3} = case Action of 
     <<"registered">> -> is_registered(Req2) 
    end, 

    {ok, Req4} = cowboy_req:reply(200, [{<<"content-type">>, <<"application/json">>}], Reply, Req3), 
    {ok, Req4, State} 
. 

is_registered(Req) -> 
    {Number, Req2} = cowboy_req:qs_val(<<"number">>, Req), 
    Reply = backend:is_registered(Number), 
    {Reply, Req2} 
. 

is_registered [기능]

is_registered(Number) -> 
    emysql:prepare(is_registered, <<"SELECT `device`.`id` FROM `device` WHERE `device`.`number`= ?">>), 
    ResultPacket = emysql:execute(auth_pool, is_registered, [Number]), 
    ResultType = is_record(ResultPacket, result_packet), 

    case ResultType of 
     true -> 
      Field = emysql_util:as_proplist(ResultPacket), 
      Id = proplists:get_value(<<"device.id">>, Field), 
      Registered = Id >= 0, 

      case Registered of 
       true -> 
        Reply = {[{response, registered}]}, 
        jiffy:encode(Reply) 
       ; 
       false -> 
        Reply = {[{response, available}]}, 
        jiffy:encode(Reply) 
      end; 
     false -> 
      Reply = {[{response, error}]}, 
      jiffy:encode(Reply) 
    end 
. 

서버는 적절한 응답으로 응답하고 모든 요청 후 case_clause 오류가 발생하는

= ERROR REPORT ==== 2014 년 2 월 5 일 : : 10 : 32 : 39 === 출구 값이있는 노드 'keychain @ dnldd'의 < 0.182.0> 오류 : {{case_clause, {ok, {http_req, # 포트 < 0.2286>, ranch_tcp, keepalive, < > 0.182.0, < < 4 바이트 >> "HTTP/1.1"{{} 127,0,0,1, 49,720} < < >> 9 바이트, 정의, 4004, 11 < < 바이트> > 정의되지 < < 0 바이트 >> [] [{작용 < < 10 바이트 >>}], [{< < 4 >> 바이트, 14 바이트 < < >>}, {< < 10 바이트 >>, < < 10 by TES >>}, {< < 14 바이트 >> < < 1 바이트 >>}, {< < >> 13 바이트, 8 바이트 < < >>}, {< < >> 6 바이트, 51 바이트 < < >>}, {< < 6 >> 바이트, 12 바이트 < < >>}, {< < >> 12 바이트, 16 바이트 < < >>}, {< < 10 바이트 >> < < 120 바이트 >>}, {< < 13 바이트 >>, < < 36 바이트 >>}, {< < 6 바이트 >> < < 3 바이트 >>}, {3 < < 바이트 >> < < 1 바이트 >>}, {< < >> 15 바이트, 17 바이트 < < >>}, {< < 15 바이트 >> < < 14 바이트 >>}], [{< < 12 바이트 >> {< < 11 바이트 >> < < 4 바이트 >> []}} , {< 바이트 >>, 정의되지 않음} {< < 13 바이트 >>, 정의되지 않음} {< 미정 미정 < 19 바이트 >>}, {< < 8 바이트 >>}, {< < 6 바이트 >> [...

= 에러 REPORT ==== 5 2 월 2014 : : 10 : 32 : 39 === 목장 청취자 keychain_http의 연결 프로세스가 으로 시작했습니다. cowboy_protocol : start_link/4 at < 0.182.0> 이유가있는 종료 : {{case_clause, {ok, {http_req, # Port < 0.2286> ranch_tcp, keepalive, < 0.182.0>, < < "POST">>, "HTTP/1.1", {{127,0,0,1}, 49720}, < < "127.0.0.1">>, 정의되지 않음, 4004, < < "/ 등록 ">> 미정, < < >> [] [{작용 < <"등록 ">> {127.0.0.1:4004" "< < >>"호스트 >>}] < <} [ " {< < "연결">>, < <가 "연결 유지">>}, {< < "내용 길이를">>, < < "0">>}, {< < "캐시 제어"> >, < < "no-cache">>}, {< < "ori 진 ">>, < <"크롬 확장 : // fhbjgbiflinjbdggehcddcbncdddomop ">>}, {< <"번호 ">>, < <"233265256262 ">>}, {< <"콘텐츠 유형 ">>, < < "application/json">>}, {< < "user-agent">>, < < "Mozilla/5.0 (Macintosh; 인텔 맥 OS X 10_8_5) AppleWebKit/537.36 (KHTML, 게코) 크롬/32.0.1700.107 사파리/537.36 ">>}, {< <"우체부 토큰 ">>, < <"61b7c8f0-b4f8-3bde- 같은 8b99-67c141242e5a ">>}, {< <" "{} >> < <를"1 "< < >>"DNT "< < {} >>"/ "< < >>"수락 accept-encoding ">>, < <"gzip, deflate, sdch ">>}, {< "accept-language ">>, < <"en-US, en; q = 0.8 ">>}], {< < "conten t-type ">>, {< <"application ">>, < <"json ">> []}}, {< <"if-modified-since ">> 정의되지 않은}, {< <"if 정의되지 않음}, {< < "accept">>, 일치하지 않는 경우 >>, 정의되지 않음}, {< < "일치하지 않는 경우 >>", undefined}, {< < " [{{< < "">> < < "">> []}, 1000 []}]}, {< < "연결">> [< < "킵 얼라이브">> ]}], 정의되지 않음, {{charset, undefined}, {media_type, {< < "text">>, < >> true, done, [], < < >>, undefined}, undefined}}, [{cowboy_rest, process_content_type, 3, [{file, "src/cowboy_rest.erl"}, {line, 780}}}, {cowboy_protocol, execute, 4, {{file, "src/cowboy_protocol.erl"}, {line, 529}}}}}

내가 뭘 잘못하고 있니? 감사.

{확인, 필수, 주}

에 :

답변

0

것은에서 handle_request에 반환 튜플을 변경해보십시오

{사실, 필수, 주}

+0

거푸집이 없습니다. 'ok'를 'true'로 대체하면 function_clause 오류가 발생합니다. – dnldd

1

내가 알아 냈어 요청에 대한 응답을 설정하고 retu해야합니다. 그거야. cowboy_rest는 실제 응답을 자동으로 처리합니다.

handle_request(Req, State) -> 
    {Action, Req2} = cowboy_req:binding(action, Req), 

    {Reply, Req3} = case Action of 
     <<"registered">> -> is_registered(Req2) 
    end, 

    Req3 = cowboy_req:set_resp_body(Reply, Req3), 
    {true, Req2, State} 
. 
+0

'Req3'은 사용하지 않는 것 같습니다. 이것은 오타입니까? 마지막 줄은'{true, Req3, State}'가 아니어야합니까? 그리고 '사실'은 어떨까요? mkorszun의 대답에 대한 귀하의 의견에서 '사실'이라고 대답 한 것은 효과가 없었습니까? – TNT