HueError.js
1.15 KB
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
62
63
64
65
66
67
68
69
'use strict';
//TODO create wrapper types
const ERROR_TYPES = {
1: 'unauthorized user',
2: 'body contains invalid JSON',
3: 'resource not found',
4: 'method not available for resource',
5: 'missing paramters in body',
6: 'parameter not available',
7: 'invalid value for parameter',
8: 'parameter not modifiable',
11: 'too many items in list',
12: 'portal connection is required',
901: 'bridge internal error',
}
class HueError {
constructor(payload) {
this.payload = payload;
}
/**
* @returns {number}
*/
get type() {
return this.payload.type || -1;
}
/**
* @returns {string}
*/
get address() {
return this.payload.address;
}
/**
* @returns {string}
*/
get description() {
return this.payload.description;
}
/**
* @returns {string}
*/
get message() {
let str = this.payload.message
, type = this.type
;
if (type === 5 || type === 6) {
// The address makes the error more meaningful
str = `${str}: ${this.address}`;
}
return str;
}
/**
* @returns {*}
*/
get rawError() {
return this.payload;
}
}
module.exports = HueError;