oklahomer / p5-Facebook-OpenGraph

https://metacpan.org/release/Facebook-OpenGraph
Other
14 stars 5 forks source link

cannot access response headers for non-successful requests #29

Open sherrardb opened 5 years ago

sherrardb commented 5 years ago

please forgive me if this has been addressed or covered elsewhere.

when encountering API limits, or other requests that result in a non-successful response, FB sometimes provides useful information in the response headers. in our specific case, we occasionally receive

4:- OAuthException:(#4) Application request limit reached
POST /v2.9/ HTTP/1.1
Connection: keep-alive
User-Agent: Facebook::OpenGraph/1.23
Authorization: OAuth ####################
Content-Type: application/x-www-form-urlencoded
Content-Length: 72
Host: graph.facebook.com

there should be a response header 'x-app-usage' that allows us to determine which limit we have exceeded

print $response->header('x-app-usage')."\n";
{"call_count":19,"total_cputime":0,"total_time":40}

but of course since the request method only returns the response object on is_success(), we cannot access that header.

of course i recognize that this is a complex issue from the perspective of the interface that you provide to the FB API, and that indicating failure while still providing access to structured data is not a straight-forward endeavor. my only thoughts as to possible approaches are the method used by DBI where additional error information is available through object and class variables

      $dbh = DBI->connect($data_source, $username, $password)
                or die $DBI::errstr;
      $dbh->commit or die $dbh->errstr;

thanks in advance for your consideration, and please let me know if i need to mock up a proper pull request, or provide further clarification.

oklahomer commented 5 years ago

That's a reasonable request. Let me take a look at the current implementation and what can be done during this weekend.

sherrardb commented 2 years ago

i know that this is a very old request, but i was just circling back to an internal ticket that depends on this and thought to check to see what you had discovered.