source: trip-planner-front/node_modules/errno/custom.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1var prr = require('prr')
2
3function init (type, message, cause) {
4 if (!!message && typeof message != 'string') {
5 message = message.message || message.name
6 }
7 prr(this, {
8 type : type
9 , name : type
10 // can be passed just a 'cause'
11 , cause : typeof message != 'string' ? message : cause
12 , message : message
13 }, 'ewr')
14}
15
16// generic prototype, not intended to be actually used - helpful for `instanceof`
17function CustomError (message, cause) {
18 Error.call(this)
19 if (Error.captureStackTrace)
20 Error.captureStackTrace(this, this.constructor)
21 init.call(this, 'CustomError', message, cause)
22}
23
24CustomError.prototype = new Error()
25
26function createError (errno, type, proto) {
27 var err = function (message, cause) {
28 init.call(this, type, message, cause)
29 //TODO: the specificity here is stupid, errno should be available everywhere
30 if (type == 'FilesystemError') {
31 this.code = this.cause.code
32 this.path = this.cause.path
33 this.errno = this.cause.errno
34 this.message =
35 (errno.errno[this.cause.errno]
36 ? errno.errno[this.cause.errno].description
37 : this.cause.message)
38 + (this.cause.path ? ' [' + this.cause.path + ']' : '')
39 }
40 Error.call(this)
41 if (Error.captureStackTrace)
42 Error.captureStackTrace(this, err)
43 }
44 err.prototype = !!proto ? new proto() : new CustomError()
45 return err
46}
47
48module.exports = function (errno) {
49 var ce = function (type, proto) {
50 return createError(errno, type, proto)
51 }
52 return {
53 CustomError : CustomError
54 , FilesystemError : ce('FilesystemError')
55 , createError : ce
56 }
57}
Note: See TracBrowser for help on using the repository browser.