/
error.js
47 lines (40 loc) · 1.16 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
Faye.Error = Faye.Class({
initialize: function(code, params, message) {
this.code = code;
this.params = Array.prototype.slice.call(params);
this.message = message;
},
toString: function() {
return this.code + ':' +
this.params.join(',') + ':' +
this.message;
}
});
Faye.Error.parse = function(message) {
message = message || '';
if (!Faye.Grammar.ERROR.test(message)) return new this(null, [], message);
var parts = message.split(':'),
code = parseInt(parts[0]),
params = parts[1].split(','),
message = parts[2];
return new this(code, params, message);
};
<% %w[ VERSION_MISMATCH
CONNTYPE_MISMATCH
EXT_MISMATCH
BAD_REQUEST
CLIENT_UNKNOWN
PARAMETER_MISSING
CHANNEL_FORBIDDEN
CHANNEL_UNKNOWN
CHANNEL_INVALID
EXT_UNKNOWN
PUBLISH_FAILED
SERVER_ERROR ].each do |error_type|
code, message = Faye::Error.const_get(error_type)
js_method = error_type.downcase.gsub(/_(.)/) { $1.upcase }
%>
Faye.Error.<%= js_method %> = function() {
return new this(<%= code %>, arguments, <%= message.inspect %>).toString();
};
<% end %>