Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle connection refused as Httpful\Response #260

Open
ghost opened this issue Jun 5, 2017 · 0 comments
Open

How to handle connection refused as Httpful\Response #260

ghost opened this issue Jun 5, 2017 · 0 comments

Comments

@ghost
Copy link

ghost commented Jun 5, 2017

I have a HTTP_CLIENT class which is pretty thing - allows me to accept parameters and call the HTTPful library while doing some logging before and after the call, it's functions just return the raw response from \Httpful\Request::post and \Httpful\Request::get. It all works fine as long as the API I am calling is up, however if it has fallen over the below seems to happen.

$res = \Httpful\Request::post($uri)              
              ->body($body)
              ->sendsJSON()
              ->expectsJSON()
              ->send();

Results in an exception being thrown of type Httpful\Exception\ConnectionErrorException which I can catch no problem, but my issues comes when trying to return a useful value to the calling code.

I would like to be able to log the error and return a \Httpful\Response with a 500 error to the calling code. Is there an easy way to either just create a response object myself and return that, or in the POST and GET calls, have it not throw an exception but return the \Httpful\Response object (probably more elegant).

I've tried to create the \Httpful\Response object myself but can't seem to get it to construct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants