Skip to content

Commit bf0ff1b

Browse files
committed
Message error as string (splicit message) instead of code error
1 parent 3dd34b8 commit bf0ff1b

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

src/core/error.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11

22
dop.core.error = {
33

4-
warning: {
5-
TOKEN_REJECTED: 'User disconnected because is rejecting too many times the token assigned'
6-
},
4+
// warning: {
5+
// TOKEN_REJECTED: 'User disconnected because is rejecting too many times the token assigned'
6+
// },
77

88
reject: {
9-
// OBJECT_ALREADY_SUBSCRIBED: 'The object "%s" is already subscribed',
10-
OBJECT_NOT_FOUND: 'Object not found to be subscribed',
9+
OBJECT_NOT_FOUND: 'Object not found',
1110
SUBSCRIPTION_NOT_FOUND: 'Not subscription found to unsubscribe this object',
1211
}
1312

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

2-
dop.core.getRejectError = function(error) {
3-
if (typeof error == 'number' && dop.core.error.reject[error] !== undefined) {
4-
var args = Array.prototype.slice.call(arguments, 1);
5-
args.unshift(dop.core.error.reject[error]);
6-
return dop.util.sprintf.apply(this, args);
7-
}
8-
return error;
9-
};
2+
// dop.core.getRejectError = function(error) {
3+
// if (typeof error == 'number' && dop.core.error.reject[error] !== undefined) {
4+
// var args = Array.prototype.slice.call(arguments, 1);
5+
// args.unshift(dop.core.error.reject[error]);
6+
// return dop.util.sprintf.apply(this, args);
7+
// }
8+
// return error;
9+
// };

src/protocol/_onsubscribe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dop.protocol._onsubscribe = function(node, request_id, request, response) {
44
if (response[0] !== undefined) {
55

66
if (response[0] !== 0)
7-
request.promise.reject(dop.core.getRejectError(response[0], request[2]));
7+
request.promise.reject(response[0]);
88

99
else {
1010
var object_path = typeof response[1]=='number' ? [response[1]] : response[1],

src/protocol/onsubscribe.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,26 @@ dop.protocol.onsubscribe = function(node, request_id, request) {
1818
dop.core.storeSendMessages(node, response);
1919
return object;
2020
}
21+
else if (value === undefined)
22+
return Promise.reject(dop.core.error.reject.OBJECT_NOT_FOUND);
2123
else
2224
// http://www.2ality.com/2016/03/promise-rejections-vs-exceptions.html
2325
// http://stackoverflow.com/questions/41254636/catch-an-error-inside-of-promise-resolver
2426
dop.util.invariant(false, 'dop.onsubscribe callback must return or resolve a regular object');
2527

2628

27-
}, function reject(error) {
28-
var response = dop.core.createResponse(request_id);
29-
(error instanceof Error) ? console.log(error.stack) : response.push(error);
30-
dop.core.storeSendMessages(node, response, JSON.stringify);
31-
}, function(req) {
29+
}, reject, function(req) {
3230
req.node = node;
3331
return req;
3432
});
3533

3634
}
35+
else
36+
reject(dop.core.error.reject.OBJECT_NOT_FOUND);
3737

38+
function reject(error) {
39+
var response = dop.core.createResponse(request_id);
40+
(error instanceof Error) ? console.log(error.stack) : response.push(error);
41+
dop.core.storeSendMessages(node, response, JSON.stringify);
42+
}
3843
};

src/util/sprintf.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

2-
dop.util.sprintf = function() {
2+
// dop.util.sprintf = function() {
33

4-
var s = -1, result, str=arguments[0], array = Array.prototype.slice.call(arguments, 1);
5-
return str.replace(/"/g, "'").replace(/%([0-9]+)|%s/g , function() {
4+
// var s = -1, result, str=arguments[0], array = Array.prototype.slice.call(arguments, 1);
5+
// return str.replace(/"/g, "'").replace(/%([0-9]+)|%s/g , function() {
66

7-
result = array[
8-
(arguments[1] === undefined || arguments[1] === '') ? ++s : arguments[1]
9-
];
7+
// result = array[
8+
// (arguments[1] === undefined || arguments[1] === '') ? ++s : arguments[1]
9+
// ];
1010

11-
if (result === undefined)
12-
result = arguments[0];
11+
// if (result === undefined)
12+
// result = arguments[0];
1313

14-
return result;
14+
// return result;
1515

16-
});
16+
// });
1717

18-
};
19-
// Usage: sprintf('Code error %s for %s', 25, 'Hi') -> "Code error 25 for Hi"
20-
// Usage2: sprintf('Code error %1 for %0', 25, 'Hi') -> "Code error Hi for 25"
18+
// };
19+
// // Usage: sprintf('Code error %s for %s', 25, 'Hi') -> "Code error 25 for Hi"
20+
// // Usage2: sprintf('Code error %1 for %0', 25, 'Hi') -> "Code error Hi for 25"

test/transports/subscribe.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ server.on('connect', function(node) {
2020
serverClient = node;
2121
})
2222

23+
test('Before onsubscribe is defined', function(t) {
24+
client.subscribe('DATA').catch(function(err){
25+
t.equal(err, dopClient.core.error.reject.OBJECT_NOT_FOUND, 'Object not found');
26+
t.end()
27+
})
28+
})
2329

2430

2531
test('Client subscribe synchronously', function(t) {
@@ -73,8 +79,8 @@ test('Client subscribe synchronously', function(t) {
7379
else if (name === 'REJECT') {
7480
req.reject({message:'Subscription rejected'})
7581
}
76-
else if (name === 'NOOBJECT') {
77-
req.resolve('NOOBJECT');
82+
else if (name === 'RESOLVESTRING') {
83+
req.resolve('RESOLVESTRING');
7884
setTimeout(t.end.bind(t), 10);
7985
}
8086
})
@@ -122,7 +128,11 @@ test('Client subscribe synchronously', function(t) {
122128
})
123129
.catch(function(err){
124130
t.equal(err.message, 'Subscription rejected', 'Subscription rejected');
125-
return client.subscribe('NOOBJECT');
131+
return client.subscribe();
132+
})
133+
.catch(function(err){
134+
t.equal(err, dopClient.core.error.reject.OBJECT_NOT_FOUND, 'Object not found');
135+
return client.subscribe('RESOLVESTRING');
126136
})
127137
// .catch(function(err){
128138
// console.log( 123131, typeof err );

0 commit comments

Comments
 (0)