forked from hove-io/NavitiaComponent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavitiaExceptionFactory.php
65 lines (60 loc) · 2.19 KB
/
NavitiaExceptionFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Navitia\Component;
use Navitia\Component\FactoryInterface;
use Navitia\Component\Exception\NavitiaException;
class NavitiaExceptionFactory implements FactoryInterface
{
private $httpCodes;
private $errorIds;
public function __construct()
{
$this->httpCodes = array(
400 => 'Navitia\Component\Exception\NavitiaBadRequestException',
401 => 'Navitia\Component\Exception\NavitiaUnauthorizedException',
403 => 'Navitia\Component\Exception\NavitiaForbiddenException',
404 => 'Navitia\Component\Exception\NavitiaNotFoundException',
0 => 'Navitia\Component\Exception\NavitiaNotRespondingException'
);
$this->errorIds = array(
'date_out_of_bounds' => 'Navitia\Component\Exception\NotFound\DateOutOfBoundsException',
'no_origin' => 'Navitia\Component\Exception\NotFound\NoOriginException',
'no_destination' => 'Navitia\Component\Exception\NotFound\NoDestinationException',
'no_origin_nor_destination' => 'Navitia\Component\Exception\NotFound\NoOriginNorDestinationException',
'unknown_object' => 'Navitia\Component\Exception\NotFound\UnknownObjectException',
);
}
/**
* {@inheritDoc}
*/
public function create($httpCode, $errorId = '', $message = '')
{
switch ($httpCode) {
case 0:
return new $this->httpCodes[$httpCode](
'Navitia timeout',
$httpCode
);
break;
case 404:
return new $this->errorIds[$errorId](
'Navitia error message: ' . $message,
$httpCode,
$errorId
);
break;
case 400:
case 401:
case 403:
return new $this->httpCodes[$httpCode](
'Navitia access error',
$httpCode
);
break;
default:
return new NavitiaException(
'Navitia error message: ' . $message,
$httpCode
);
}
}
}