-
Notifications
You must be signed in to change notification settings - Fork 7
/
error.js
72 lines (63 loc) · 1.68 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
62
63
64
65
66
67
68
69
70
71
72
const parser = require('fast-xml-parser');
const code = {
NO_SERVICE: 'NO_SERVICE',
NO_ACTION: 'NO_ACTION',
NO_EVENTS: 'NO_EVENTS',
UPNP: 'UPNP',
SUBSCRIBE: 'SUBSCRIBE',
SUBSCRIBE_RENEW: 'SUBSCRIBE_RENEW',
UNSUBSCRIBE: 'UNSUBSCRIBE'
}
function NoService(serviceId) {
const err = new Error(`Service ${serviceId} not provided by device`);
err.code = code.NO_SERVICE;
return err;
}
function NoAction(serviceId) {
const err = new Error(`Action ${serviceId} not implemented by service`);
err.code = code.NO_ACTION;
return err;
}
function UPnPError(statusCode, xmlString) {
const envelope = parser.parse(xmlString);
const error = envelope['s:Envelope']['s:Body']['s:Fault'].detail.UPnPError;
const { errorCode, errorDescription } = error;
const err = new Error(`(${errorCode}) ${errorDescription}`);
err.code = code.UPNP;
err.statusCode = statusCode;
err.errorCode = errorCode;
return err;
}
function NoEvents(variable) {
const err = new Error(`Variable ${variable} does not generate event messages`);
err.code = code.NO_EVENTS;
return err;
}
function Subscribe(statusCode) {
const err = new Error('Subscription error');
err.code = code.SUBSCRIBE;
err.statusCode = statusCode;
return err;
}
function SubscriptionRenewal(statusCode) {
const err = new Error('Subscription renewal error');
err.code = code.SUBSCRIBE_RENEW;
err.statusCode = statusCode;
return err;
}
function Unsubscribe(statusCode) {
const err = new Error('Unsubscription error');
err.code = code.UNSUBSCRIBE;
err.statusCode = statusCode;
return err;
}
module.exports = {
code,
NoService,
NoAction,
NoEvents,
UPnPError,
Subscribe,
SubscriptionRenewal,
Unsubscribe
}