UNPKG

731 BJavaScriptView Raw
1/**
2 * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
3 */
4'use strict';
5
6module.exports = class Exception {
7
8 constructor (err, data) {
9 if (err instanceof Exception) {
10 Object.assign(this, err);
11 } else if (err instanceof Error) {
12 this.message = err.message;
13 this.data = err.stack;
14 this.error = err;
15 } else if (typeof err === 'string') {
16 this.message = err;
17 if (data !== undefined) {
18 this.data = data;
19 }
20 } else if (err !== undefined) {
21 this.data = err;
22 }
23 }
24
25 toString () {
26 return this.message || this.data;
27 }
28};
\No newline at end of file