-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathServerException.php
121 lines (108 loc) · 2.74 KB
/
ServerException.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* ArangoDB PHP client: server exception
*
* @package ArangoDBClient
* @author Jan Steemann
* @copyright Copyright 2012, triagens GmbH, Cologne, Germany
*/
namespace ArangoDBClient;
/**
* Server-Exception
*
* This exception type will be thrown by the client when the server returns an
* error in response to a client request.
*
* The exception code is the HTTP status code as returned by
* the server.
* In case the server provides additional details
* about the error, these details can be queried using the
* getDetails() function.<br>
* <br>
*
* @package ArangoDBClient
* @since 0.2
*/
class ServerException extends Exception
{
/**
* Optional details for the exception
*
* @param array
*/
private $_details = [];
/**
* Error number index
*/
const ENTRY_CODE = 'errorNum';
/**
* Error message index
*/
const ENTRY_MESSAGE = 'errorMessage';
/**
* Return a string representation of the exception
*
* @return string - string representation
*/
public function __toString()
{
return __CLASS__ . ': ' . $this->getServerCode() . ' ' . $this->getMessage();
}
/**
* Set exception details
*
* If the server provides additional details about the error
* that occurred, they will be put here.
*
* @param array $details - array of exception details
*
* @return void
*/
public function setDetails(array $details)
{
$this->_details = $details;
}
/**
* Get exception details
*
* If the server has provided additional details about the error
* that occurred, they can be queries using the method
*
* @return array - array of details
*/
public function getDetails()
{
return $this->_details;
}
/**
* Get server error code
*
* If the server has provided additional details about the error
* that occurred, this will return the server error code
*
* @return int - server error code
*/
public function getServerCode()
{
if (isset($this->_details[self::ENTRY_CODE])) {
return $this->_details[self::ENTRY_CODE];
}
return $this->getCode();
}
/**
* Get server error message
*
* If the server has provided additional details about the error
* that occurred, this will return the server error string
*
* @return string - server error message
*/
public function getServerMessage()
{
if (isset($this->_details[self::ENTRY_MESSAGE])) {
return $this->_details[self::ENTRY_MESSAGE];
}
return null;
}
}
class_alias(ServerException::class, '\triagens\ArangoDb\ServerException');