UNPKG

968 BJavaScriptView Raw
1const assert = require('assert');
2
3/**
4 * Class representing a SIP non-success response to a transaction
5 * @extends {Error}
6 */
7class SipError extends Error {
8
9 /**
10 * Create a SipError object
11 *
12 * @constructor
13 * @param {number} status SIP final status
14 * @param {string} [reason] reason for failure; if not provided
15 * the standard reason associated with the provided SIP status is used
16 */
17 constructor(...args /*status, reason*/) {
18 super(...args) ;
19
20 assert.ok(typeof args[0] === 'number', 'first argument to SipError must be number');
21 assert.ok(typeof args[1] === 'string' || typeof args[1] === 'undefined',
22 'second argument to SipError, if provided, must be a string');
23
24 this.name = 'SipError' ;
25 this.status = args[0] ;
26 if (args[1]) this.reason = args[1] ;
27 this.message = 'Sip non-success response: ' + this.status ;
28
29 Error.captureStackTrace(this, SipError);
30 }
31}
32
33module.exports = exports = SipError ;