2017-02-20 88 views
0

我正在向http 500發送一個Remote::get請求,該請求在出現問題時出錯。問題在於它也給出了{errorCode: x}作爲對響應文本中出錯的更詳細的描述。在一些錯誤代碼中,我需要採取不同的行動。使用Kohana Remote ::在http 500上獲取拋出異常,但我需要響應文本

我的問題是,Kohana在http 500響應中拋出異常,從而在異常對象中的「羅嗦」錯誤消息中烘焙我簡單的可解析響應文本。

是否有某種方法可以在http 500響應中獲得Remote::get的響應文本,而無需解析冗長的錯誤描述?

回答

1

不可能。看看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沒有太大的幫助

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); 
} 

所以它混合所有的東西到一個消息。

如何使用不同的HTTP客戶端?例如Guzzle - retrieve the body on error更容易。

相關問題