MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / readError

Method readError

lib/readers.js:388–473  ·  view source on GitHub ↗

* Reads the error from the frame * @throws {RangeError} * @returns {ResponseError}

()

Source from the content-addressed store, hash-verified

386 * @returns {ResponseError}
387 */
388 readError() {
389 const code = this.readInt();
390 const message = this.readString();
391 const err = new errors.ResponseError(code, message);
392 //read extra info
393 switch (code) {
394 case types.responseErrorCodes.unavailableException:
395 err.consistencies = this.readShort();
396 err.required = this.readInt();
397 err.alive = this.readInt();
398 err.message = util.format(_unavailableMessage, types.consistencyToString[err.consistencies], err.required, err.alive);
399 break;
400 case types.responseErrorCodes.readTimeout:
401 case types.responseErrorCodes.readFailure:
402 err.consistencies = this.readShort();
403 err.received = this.readInt();
404 err.blockFor = this.readInt();
405 if (code === types.responseErrorCodes.readFailure) {
406 if (types.protocolVersion.supportsFailureReasonMap(this.header.version)) {
407 err.failures = this.readInt();
408 err.reasons = this.readMap(err.failures, this.readInetAddress, this.readShort);
409 }
410 else {
411 err.failures = this.readInt();
412 }
413 }
414 err.isDataPresent = this.readByte();
415 if (code === types.responseErrorCodes.readTimeout) {
416 let details;
417 if (err.received < err.blockFor) {
418 details = util.format('%d replica(s) responded over %d required', err.received, err.blockFor);
419 }
420 else if (!err.isDataPresent) {
421 details = 'the replica queried for the data didn\'t respond';
422 }
423 else {
424 details = 'timeout while waiting for repair of inconsistent replica';
425 }
426 err.message = util.format(_readTimeoutMessage, types.consistencyToString[err.consistencies], details);
427 }
428 else {
429 err.message = util.format(_readFailureMessage, types.consistencyToString[err.consistencies], err.blockFor, err.received, err.failures);
430 }
431 break;
432 case types.responseErrorCodes.writeTimeout:
433 case types.responseErrorCodes.writeFailure:
434 err.consistencies = this.readShort();
435 err.received = this.readInt();
436 err.blockFor = this.readInt();
437 if (code === types.responseErrorCodes.writeFailure) {
438 if (types.protocolVersion.supportsFailureReasonMap(this.header.version)) {
439 err.failures = this.readInt();
440 err.reasons = this.readMap(err.failures, this.readInetAddress, this.readShort);
441 }
442 else {
443 err.failures = this.readInt();
444 }
445 }

Callers 1

streams.jsFile · 0.80

Calls 7

readIntMethod · 0.95
readStringMethod · 0.95
readShortMethod · 0.95
readMapMethod · 0.95
readByteMethod · 0.95
readShortBytesMethod · 0.95
readStringListMethod · 0.95

Tested by

no test coverage detected