nategood/httpful

Question on \Httpful\Request::whenError() usage

kaldimar opened this issue · 0 comments

How can I intercept and handle errors found during post requests? I've found the whenError() method from the Request class, and the provided callback is in fact being invoked, however the $error argument comes null. Maybe you can provide a basic usage example? Here is how I'm using it:

$response = \Httpful\Request::post($url, json_encode($data))
    ->addHeaders($this->getHeaders())
    ->followRedirects(true)
    ->whenError(call_user_func([$this, $callback]))
    ->expectsJson()
    ->send();

Here $callback is a string with the name of the method in my current controller class where I expect to handle errors, it has signature errorHandler($error = null, $response = [])