These forums have been archived and are now read-only.

The new forums are live and can be found at https://forums.eveonline.com/

EVE Technology Lab

 
  • Topic is locked indefinitely.
 

Handling API errors and 403s [PHP]

Author
Viomi
Garoun Investment Bank
Gallente Federation
#1 - 2013-08-31 00:23:18 UTC
So I was wondering how to deal with things like;

This error code in xml here

I was looking at doing something similar to below, however it seemed to throw up the error below the code;

Quote:
$apiSection = "/char/KillLog";
$urlChar = "https://api.eveonline.com/$apiSection.xml.aspx?keyID=$keyID&vCode=$vCode&characterID=$charID";
[Line 79] - $data = file_get_contents($urlChar);
[Line 80]- $xml = new SimpleXMLElement($data);

if ($xml->error{'code'}==119){
echo "Can't look up kills that often";
}


Quote:
Warning: file_get_contents(https://api.eveonline.com//char/KillLog.xml.aspx?keyID=XXXXX&vCode=XXXXXXXXXXXXXXXXXXX&characterID=XXXXXXX): failed to open stream: HTTP request failed! HTTP/1.1 000 in /Users/Jamie/Sites/eve/corporation.php on line 79

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /Users/jamieprentice/Sites/eve/corporation.php:80 Stack trace: #0 /Users/jamieprentice/Sites/eve/corporation.php(80): SimpleXMLElement->__construct('') #1 {main} thrown in /Users/Jamie/Sites/eve/corporation.php on line 80


I was wondering how to handle these and display something instead of getting that kind of error message - that one being just an example - I know there are loads of error codes listed here https://wiki.eveonline.com/en/wiki/EVE_API_EVE_Error_List.

Then I'm also wondering how you handle the 403 forbidden screens - whats the best way to deal with it?

Thanks for your time,

Viomi! :)
0mni Ca
Brutor Tribe
Minmatar Republic
#2 - 2013-08-31 06:39:40 UTC
You can see how I handle errors here:
http://drupalcode.org/project/eve_api.git/blob/511b8f7a699e0c821bc192d35df5bb2a14baf5f7:/eve_api.api.inc

The function I use to handle the getting the XML and making sure it is valid is:

Quote:
function eve_api_get_xml($type, $query = array()) {


Starts at line 18
Peter Powers
Terrorists of Dimensions
HORSE-KILLERS
#3 - 2013-08-31 14:14:55 UTC
i'd recommend to use an API library such as PhealNG, which will allow you to surround your code with try/catch to catch this and other exceptions (and also provides you with proper cache handling etc).

3rdPartyEve.net - your catalogue for 3rd party applications