Skip to content

Handling Exceptions

Leon Jacobs edited this page May 16, 2018 · 2 revisions

SeAT

Handling Exceptions

Failed requests should throw a Seat\Eseye\Exceptions\RequestFailedException which you should handle in your application. The error code for the Exception itself will be the HTTP response code (so something like $e->getCode()). You can also get the HTTP response code (and message) by getting the EsiResponse from the RequestFailedException with something like $e->getEsiResponse()->getErrorCode().

Lets look at a small example to handle errors.

<?php

include 'vendor/autoload.php';

$client_id = 'invalid';
$secret_key = 'invalid';
$refresh_token = 'invalid';

$authentication = new \Seat\Eseye\Containers\EsiAuthentication([
    'client_id'     => $client_id,
    'secret'        => $secret_key,
    'refresh_token' => $refresh_token,
]);

$esi = new \Seat\Eseye\Eseye($authentication);

try {

    $contacts = $esi->invoke('get', '/characters/{character_id}/contacts', [
        'character_id' => 1477919642,
    ]);

} catch (\Seat\Eseye\Exceptions\RequestFailedException $e) {

    // The HTTP Response code and message can be retreived
    // from the exception...
    print $e->getCode() . PHP_EOL;
    print $e->getMessage() . PHP_EOL;

    // .. or from the EsiResponse available from the Exception
    print $e->getEsiResponse()->getErrorCode() . PHP_EOL;
    print $e->getEsiResponse()->error() . PHP_EOL;

    // You can also access the *actual* response we got from
    // ESI as a normal array.
    print_r($e->getEsiResponse());
}