-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy patherror.js
61 lines (50 loc) · 1.01 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Module dependencies.
*/
var inherits = require('util').inherits;
/**
* Error "domains".
*/
var domains = {
11: 'AuthorizationError',
12: 'TrackError',
13: 'HermesError',
14: 'HermesServiceError'
};
/**
* Error "codes".
*/
var codes = {
0: 'Account subscription status not Spotify Premium',
1: 'Failed to send to backend',
8: 'Rate limited',
408: 'Timeout',
429: 'Too many requests'
};
/**
* Module exports.
*/
module.exports = SpotifyError;
/**
* Spotify error class.
*
* Sample `err` objects:
*
* [ 11, 1, 'Invalid user' ]
* [ 12, 8, '' ]
* [ 14, 408, '' ]
* [ 14, 429, '' ]
*/
function SpotifyError (err) {
this.domain = err[0] || 0;
this.code = err[1] || 0;
this.description = err[2] || '';
this.data = err[3] || null;
// Error impl
this.name = domains[this.domain];
var msg = codes[this.code];
if (this.description) msg += ' (' + this.description + ')';
this.message = msg;
Error.captureStackTrace(this, SpotifyError);
}
inherits(SpotifyError, Error);