我正在向API发出Remote::get
请求,当出现问题时,该请求会以http 500
回答。问题是它还提供{errorCode: x}
作为响应文本中出错的更详细描述。在某些错误代码上,我需要采取不同的操作。
我的问题是Kohana在http 500
响应上抛出异常,因此在异常对象中的“罗嗦”错误消息中使用易于解析的响应文本进行烘焙。
是否有某种方法可以在Remote::get
响应中获取http 500
的响应文本,而无需解析冗长的错误说明?
答案 0 :(得分: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更容易。