-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp_rest_exceptions.php
More file actions
executable file
·59 lines (47 loc) · 1.93 KB
/
php_rest_exceptions.php
File metadata and controls
executable file
·59 lines (47 loc) · 1.93 KB
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
<?php
// Common Parent
abstract class WebServiceException extends Exception {
public function __construct($message, $code, Exception $previous = null) {
parent::__construct($message, $code, $previous);
}
}
// If request is invalid, missing required args, or unsupported
class BadRequestException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 400, $previous);
}
}
// If the request requires authorization but authorization headers are missing
class UnauthorizedException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 401, $previous);
}
}
// If authorization headers were provided but but user is not permissioned to do a given operation
class ForbidenException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 403, $previous);
}
}
// If the resource (data item) does not exist
// Example: requested training with id=547 does not exist
class NotFoundException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 404, $previous);
}
}
// If the operation cannot be applied to a given resource
// Example: unbook training which is not booked
class ConflictException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 409, $previous);
}
}
// Processing of the request failed
// Example: data serialization failed, db-connection failed etc.
class InternalErrorException extends WebServiceException {
public function __construct($message, Exception $previous = null) {
parent::__construct($message, 500, $previous);
}
}
?>