All files / src/errors rpc-error.js

100% Statements 10/10
100% Branches 9/9
100% Functions 4/4
100% Lines 10/10
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                            69x 1x     68x 1x 1x     68x   68x       1x       1x                 131x      
 
/**
 * Module dependencies.
 */
 
import { STATUS_CODES } from 'http';
import StandardError from './standard-error';
 
/**
 * Export `RpcError` class.
 */
 
export default class RpcError extends StandardError {
  constructor(code, msg, props = {}) {
    if (typeof code != 'number') {
      throw new TypeError(`Non-numeric HTTP code`);
    }
 
    if (typeof msg == 'object' && msg !== null) {
      props = msg;
      msg = null;
    }
 
    props.code = code;
 
    super(msg || STATUS_CODES[code], props);
  }
 
  get status() {
    return this.code;
  }
 
  set status(value) {
    Object.defineProperty(this, 'status', {
      configurable: true,
      enumerable: true,
      value,
      writable: true
    });
  }
 
  toString() {
    return `${this.name}: ${this.code} ${this.message}`;
  }
}