Skip to content

Commit bb7aeed

Browse files
committed
Adding some extra status codes to the exception class, plus added an example to satisfy #103
1 parent 8bafd38 commit bb7aeed

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

examples/exception_handling.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* This file is part of the Tmdb PHP API created by Michael Roterman.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @package Tmdb
9+
* @author Michael Roterman <[email protected]>
10+
* @copyright (c) 2013, Michael Roterman
11+
* @version 0.0.1
12+
*/
13+
header('Content-Type: text/html; charset=utf-8');
14+
15+
use Tmdb\Repository\MovieRepository;
16+
use Tmdb\Exception\TmdbApiException;
17+
18+
require_once '../vendor/autoload.php';
19+
require_once '../apikey.php';
20+
21+
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
22+
$client = new \Tmdb\Client($token);
23+
24+
$repository = new MovieRepository($client);
25+
26+
/**
27+
* @var \Tmdb\Model\Movie $movie
28+
*/
29+
try {
30+
$movie = $repository->load(298312000);
31+
} catch (TmdbApiException $e) {
32+
if (TmdbApiException::STATUS_RESOURCE_NOT_FOUND == $e->getCode()) {
33+
// not found
34+
echo '404';exit;
35+
}
36+
37+
// catch other tmdb specific errors
38+
} catch (Exception $e) {
39+
// catch any other errors
40+
}

lib/Tmdb/Exception/TmdbApiException.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,41 @@
2020
*/
2121
class TmdbApiException extends \Exception
2222
{
23+
const STATUS_SUCCESS = 1;
24+
const STATUS_INVALID_SERVICE = 2;
25+
const STATUS_AUTHENTICATION_FAILED_NO_PERMISSION = 3;
26+
const STATUS_INVALID_FORMAT = 4;
27+
const STATUS_INVALID_PARAMETERS = 5;
28+
const STATUS_INVALID_ID = 6;
29+
const STATUS_INVALID_API_KEY = 7;
30+
const STATUS_DUPLICATE_ENTRY = 8;
31+
const STATUS_SERVICE_OFFLINE = 9;
32+
const STATUS_SUSPENDED_API_KEY = 10;
33+
const STATUS_INTERNAL_ERROR = 11;
34+
const STATUS_UPDATE_SUCCESS = 12;
35+
const STATUS_DELETE_SUCCESS = 13;
36+
const STATUS_AUTHENTICATION_FAILED = 14;
37+
const STATUS_FAILED = 15;
38+
const STATUS_DEVICE_DENIED = 16;
39+
const STATUS_SESSION_DENIED = 17;
40+
const STATUS_VALIDATION_FAILED = 18;
41+
const STATUS_INVALID_ACCEPT_HEADER = 19;
42+
const STATUS_INVALID_DATE_RANGE = 20;
43+
const STATUS_ENTRY_NOT_FOUND = 21;
44+
const STATUS_INVALID_PAGE = 22;
45+
const STATUS_INVALID_DATE = 23;
46+
const STATUS_BACKEND_TIMEOUT = 24;
47+
const STATUS_REQUEST_COUNT = 25;
48+
const STATUS_USERNAME_PASSWORD_NOT_PROVIDED = 26;
49+
const STATUS_TOO_MANY_APPEND_TO_RESPONSE = 27;
50+
const STATUS_INVALID_TIMEZONE = 28;
51+
const STATUS_CONFIRM_REQUIRED = 29;
52+
const STATUS_INVALID_USERNAME_PASSWORD = 30;
53+
const STATUS_ACCOUNT_DISABLED = 31;
54+
const STATUS_EMAIL_NOT_VERIFIED = 32;
55+
const STATUS_INVALID_REQUEST_TOKEN = 33;
56+
const STATUS_RESOURCE_NOT_FOUND = 34;
57+
2358
/**
2459
* @var int
2560
*/

0 commit comments

Comments
 (0)