/
error.js
44 lines (33 loc) · 1 KB
/
error.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
// Error
// -----
import _ from 'underscore';
import extend from './utils/extend';
import {version} from '../package.json';
const errorProps = ['description', 'fileName', 'lineNumber', 'name', 'message', 'number'];
const MarionetteError = extend.call(Error, {
urlRoot: `http://marionettejs.com/docs/v${version}/`,
constructor(message, options) {
if (_.isObject(message)) {
options = message;
message = options.message;
} else if (!options) {
options = {};
}
const error = Error.call(this, message);
_.extend(this, _.pick(error, errorProps), _.pick(options, errorProps));
this.captureStackTrace();
if (options.url) {
this.url = this.urlRoot + options.url;
}
},
captureStackTrace() {
if (Error.captureStackTrace) {
Error.captureStackTrace(this, MarionetteError);
}
},
toString() {
return this.name + ': ' + this.message + (this.url ? ' See: ' + this.url : '');
}
});
MarionetteError.extend = extend;
export default MarionetteError;