2017-02-20 5 views
0

何か問題が発生したときにhttp 500と答えるAPIにRemote::getリクエストを出しています。問題は、応答テキストに何が間違っていたかについての詳細な説明として{errorCode: x}を与えることです。いくつかのエラーコードでは、私は別のアクションを取る必要があります。Kohana Remote :: getを使用するとHTTP 500で例外がスローされますが、応答テキストが必要です

私の問題は、Kohanaがhttp 500レスポンスで例外をスローし、例外オブジェクトの「ワーディー」エラーメッセージの簡単な解析可能な応答テキストを焼くことです。

Remote::getの応答テキストをhttp 500という応答で取得する方法はありますか?長いエラーの説明を解析する必要はありませんか?

答えて

1

不可能です。ずっと

public function __construct($message, array $variables = NULL, $code = 0) 
{ 
    // Set the message 
    $message = __($message, $variables); 

    // Pass the message to the parent 
    parent::__construct($message, $code); 
} 

だから、それは一つのメッセージにすべてのものをミックス助けないsource code

if ($code AND $code < 200 OR $code > 299) 
{ 
    $error = $response; 
} 

... 

if (isset($error)) 
{ 
    throw new Kohana_Exception('Error fetching remote :url [ status :code ] :error', 
      array(':url' => $url, ':code' => $code, ':error' => $error)); 
} 

Kohana_Exceptionを見てみましょう。

異なるHTTPクライアントを使用することはどうですか?例えばGuzzleのように - retrieve the body on errorの方が簡単です。

関連する問題