1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | 'use strict';
|
17 | const util = require('util');
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function DriverError (message) {
|
28 | Error.call(this, message);
|
29 | Error.captureStackTrace(this, this.constructor);
|
30 | this.name = this.constructor.name;
|
31 | this.info = 'Cassandra Driver Error';
|
32 |
|
33 | this.message = message;
|
34 | }
|
35 |
|
36 | util.inherits(DriverError, Error);
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function NoHostAvailableError(innerErrors, message) {
|
45 | DriverError.call(this, message);
|
46 | this.innerErrors = innerErrors;
|
47 | this.info = 'Represents an error when a query cannot be performed because no host is available or could be reached by the driver.';
|
48 | if (!message) {
|
49 | this.message = 'All host(s) tried for query failed.';
|
50 | if (innerErrors) {
|
51 | const hostList = Object.keys(innerErrors);
|
52 | if (hostList.length > 0) {
|
53 | const host = hostList[0];
|
54 | this.message += util.format(' First host tried, %s: %s. See innerErrors.', host, innerErrors[host]);
|
55 | }
|
56 | }
|
57 | }
|
58 | }
|
59 |
|
60 | util.inherits(NoHostAvailableError, DriverError);
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | function ResponseError(code, message) {
|
69 | DriverError.call(this, message);
|
70 | |
71 |
|
72 |
|
73 |
|
74 | this.code = code;
|
75 | this.info = 'Represents an error message from the server';
|
76 | }
|
77 |
|
78 | util.inherits(ResponseError, DriverError);
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | function DriverInternalError(message) {
|
86 | DriverError.call(this, message);
|
87 | this.info = 'Represents a bug inside the driver or in a Cassandra host.';
|
88 | }
|
89 |
|
90 | util.inherits(DriverInternalError, DriverError);
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | function AuthenticationError(message) {
|
98 | DriverError.call(this, message);
|
99 | this.info = 'Represents an authentication error from the driver or from a Cassandra node.';
|
100 | }
|
101 |
|
102 | util.inherits(AuthenticationError, DriverError);
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | function ArgumentError(message) {
|
110 | DriverError.call(this, message);
|
111 | this.info = 'Represents an error that is raised when one of the arguments provided to a method is not valid.';
|
112 | }
|
113 |
|
114 | util.inherits(ArgumentError, DriverError);
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 | function OperationTimedOutError(message, host) {
|
124 | DriverError.call(this, message, this.constructor);
|
125 | this.info = 'Represents a client-side error that is raised when the client did not hear back from the server ' +
|
126 | 'within socketOptions.readTimeout';
|
127 |
|
128 | |
129 |
|
130 |
|
131 |
|
132 | this.host = host;
|
133 | }
|
134 |
|
135 | util.inherits(OperationTimedOutError, DriverError);
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | function NotSupportedError(message) {
|
143 | DriverError.call(this, message, this.constructor);
|
144 | this.info = 'Represents a feature that is not supported in the driver or in the Cassandra version.';
|
145 | }
|
146 |
|
147 | util.inherits(NotSupportedError, DriverError);
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | function BusyConnectionError(address, maxRequestsPerConnection, connectionLength) {
|
158 | const message = util.format('All connections to host %s are busy, %d requests are in-flight on %s',
|
159 | address, maxRequestsPerConnection, connectionLength === 1 ? 'a single connection': 'each connection');
|
160 | DriverError.call(this, message, this.constructor);
|
161 | this.info = 'Represents a client-side error indicating that all connections to a certain host have reached ' +
|
162 | 'the maximum amount of in-flight requests supported (pooling.maxRequestsPerConnection)';
|
163 | }
|
164 |
|
165 | util.inherits(BusyConnectionError, DriverError);
|
166 |
|
167 | exports.ArgumentError = ArgumentError;
|
168 | exports.AuthenticationError = AuthenticationError;
|
169 | exports.BusyConnectionError = BusyConnectionError;
|
170 | exports.DriverError = DriverError;
|
171 | exports.OperationTimedOutError = OperationTimedOutError;
|
172 | exports.DriverInternalError = DriverInternalError;
|
173 | exports.NoHostAvailableError = NoHostAvailableError;
|
174 | exports.NotSupportedError = NotSupportedError;
|
175 | exports.ResponseError = ResponseError; |
\ | No newline at end of file |