-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (33 loc) · 923 Bytes
/
index.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
const scErrors = require('sc-errors');
const InvalidActionError = scErrors.InvalidActionError;
function AGRequest(socket, id, procedureName, data) {
this.socket = socket;
this.id = id;
this.procedure = procedureName;
this.data = data;
this.sent = false;
this._respond = (responseData, options) => {
if (this.sent) {
throw new InvalidActionError(`Response to request ${this.id} has already been sent`);
}
this.sent = true;
this.socket.sendObject(responseData, options);
};
this.end = (data, options) => {
let responseData = {
rid: this.id
};
if (data !== undefined) {
responseData.data = data;
}
this._respond(responseData, options);
};
this.error = (error, options) => {
let responseData = {
rid: this.id,
error: scErrors.dehydrateError(error)
};
this._respond(responseData, options);
};
}
module.exports = AGRequest;