-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathError.php
More file actions
128 lines (108 loc) · 3.7 KB
/
Copy pathError.php
File metadata and controls
128 lines (108 loc) · 3.7 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
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
122
123
124
125
126
127
128
<?php
namespace Cassandra\Response;
use Cassandra\Protocol\Frame;
class Error extends Response {
const SERVER_ERROR = 0x0000;
const PROTOCOL_ERROR = 0x000A;
const BAD_CREDENTIALS = 0x0100;
const UNAVAILABLE_EXCEPTION = 0x1000;
const OVERLOADED = 0x1001;
const IS_BOOTSTRAPPING = 0x1002;
const TRUNCATE_ERROR = 0x1003;
const WRITE_TIMEOUT = 0x1100;
const READ_TIMEOUT = 0x1200;
const SYNTAX_ERROR = 0x2000;
const UNAUTHORIZED = 0x2100;
const INVALID = 0x2200;
const CONFIG_ERROR = 0x2300;
const ALREADY_EXIST = 0x2400;
const UNPREPARED = 0x2500;
/**
* Indicates an error processing a request. The body of the message will be an
* error code ([int]) followed by a [string] error message. Then, depending on
* the exception, more content may follow. The error codes are defined in
* Section 7, along with their additional content if any.
*
* @return array
*/
public function getData() {
$this->_stream->offset(0);
$data = [];
$data['code'] = $this->_stream->readInt();
switch($data['code']){
case self::SERVER_ERROR:
$data['message'] = "Server error: " . $this->_stream->readString();
break;
case self::PROTOCOL_ERROR:
$data['message'] = "Protocol error: " . $this->_stream->readString();
break;
case self::BAD_CREDENTIALS:
$data['message'] = "Bad credentials: " . $this->_stream->readString();
break;
case self::UNAVAILABLE_EXCEPTION:
$data['message'] = "Unavailable exception. Error data: " . var_export([
'error'=>$this->_stream->readString(),
'consistency' => $this->_stream->readShort(),
'node' => $this->_stream->readInt(),
'replica' => $this->_stream->readInt()
], true);
break;
case self::OVERLOADED:
$data['message'] = "Overloaded: " . $this->_stream->readString();
break;
case self::IS_BOOTSTRAPPING:
$data['message'] = "Is_bootstrapping: " . $this->_stream->readString();
break;
case self::TRUNCATE_ERROR:
$data['message'] = "Truncate_error: " . $this->_stream->readString();
break;
case self::WRITE_TIMEOUT:
$data['message'] = "Write_timeout. Error data: " . var_export([
'error'=>$this->_stream->readString(),
'consistency' => $this->_stream->readShort(),
'node' => $this->_stream->readInt(),
'replica' => $this->_stream->readInt(),
'writeType' => $this->_stream->readString()
], true);
break;
case self::READ_TIMEOUT:
$data['message'] = "Read_timeout. Error data: " . var_export([
'error'=>$this->_stream->readString(),
'consistency' => $this->_stream->readShort(),
'node' => $this->_stream->readInt(),
'replica' => $this->_stream->readInt(),
'dataPresent' => $this->_stream->readChar()
], true);
break;
case self::SYNTAX_ERROR:
$data['message'] = "Syntax_error: " . $this->_stream->readString();
break;
case self::UNAUTHORIZED:
$data['message'] = "Unauthorized: " . $this->_stream->readString();
break;
case self::INVALID:
$data['message'] = "Invalid: " . $this->_stream->readString();
break;
case self::CONFIG_ERROR:
$data['message'] = "Config_error: " . $this->_stream->readString();
break;
case self::ALREADY_EXIST:
$data['message'] = "Already_exists: " . $this->_stream->readString();
break;
case self::UNPREPARED:
$data['message'] = "Unprepared: " . $this->_stream->readShort();
break;
default:
$data['message'] = 'Unknown error';
}
return $data;
}
/**
*
* @return Exception
*/
public function getException(){
$data = $this->getData();
return new \Exception($data['message'], $data['code']);
}
}