forked from primus/primus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.js
53 lines (43 loc) · 1.14 KB
/
errors.js
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
'use strict';
var util = require('util');
/**
* Generic Primus error.
*
* @constructor
* @param {String} message The reason for the error
* @param {EventEmitter} logger Optional EventEmitter to emit a `log` event on.
* @api public
*/
function PrimusError(message, logger) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (logger) {
logger.emit('log', 'error', this);
}
}
util.inherits(PrimusError, Error);
/**
* There was an error while parsing incoming or outgoing data.
*
* @param {String} message The reason for the error.
* @param {Spark} spark The spark that caused the error.
* @api public
*/
function ParserError(message, spark) {
Error.call(this);
Error.captureStackTrace(this, this.constructor);
this.message = message;
this.name = this.constructor.name;
if (spark) {
if (spark.listeners('error').length) spark.emit('error', this);
spark.primus.emit('log', 'error', this);
}
}
util.inherits(ParserError, Error);
//
// Expose our custom events.
//
exports.PrimusError = PrimusError;
exports.ParserError = ParserError;