Mercurial > psgxs
annotate errors.js @ 58:b98e545a94f7 default tip
Always use children instead of tags. Might break something.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 13 Sep 2011 00:54:55 +0200 |
parents | 99bd1d1ac071 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
3 * | |
4 * This file is part of PSĜS, a PubSub server written in JavaScript. | |
5 * | |
6 * PSĜS is free software: you can redistribute it and/or modify | |
7 * it under the terms of the GNU Affero General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License. | |
10 * | |
11 * PSĜS is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU Affero General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Affero General Public License | |
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. | |
18 */ | |
19 | |
43
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
40
diff
changeset
|
20 'use strict'; |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
40
diff
changeset
|
21 |
0 | 22 var errors = exports; |
23 | |
24 errors.success = true; | |
25 errors.feature_not_implemented = {n: 1, type: 'cancel', error: 'feature-not-implemented'}; | |
26 errors.node_does_not_exist = {n: 2, type: 'cancel', error: 'item-not-found'}; | |
27 errors.bad_request = {n: 3, type: 'modify', error: 'bad-request'}; | |
28 errors.nodeid_required = {n: 4, type: 'modify', error: 'bad-request', reason: 'nodeid-required'}; | |
29 errors.itemid_required = {n: 5, type: 'modify', error: 'bad-request', reason: 'item-required'}, | |
30 errors.forbidden = {n: 6, type: 'auth', error: 'forbidden'}; | |
31 errors.subscriptions_retrieval_not_supported = {n: 23, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'retrieve-subscriptions'}; | |
32 errors.affiliations_retrieval_not_supported = {n: 29, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'retrieve-affiliations'}; | |
33 | |
34 errors.sub = { | |
35 subscribe: { | |
36 jids_do_not_match: {n: 34, type: 'modify', error: 'bad-request', reason: 'invalid-jid'}, | |
37 presence_subscription_required: {n: 35, type: 'auth', error: 'not-authorized', reason: 'presence-subscription-required'}, | |
38 not_in_roster_group: {n: 36, type: 'auth', error: 'not-authorized', reason: 'not-in-roster-group'}, | |
39 not_on_whitelist: {n: 37, type: 'cancel', error: 'not-allowed', reason: 'closed-node'}, | |
40 payment_required: {n: 38, type: 'auth', error: 'payment-required'}, | |
41 anonymous_subscriptions_not_allowed: {n: 39, type: 'cancel', error: 'forbidden'}, | |
42 subscription_pending: {n: 40, type: 'auth', error: 'not-authorized', reason: 'pending-subscription'}, | |
43 blocked: {n: 41, type: 'auth', error: 'forbidden'}, | |
44 too_many_subscriptions: {n: 42, type: 'wait', error: 'policy-violation', reason: 'too-many-subscriptions'}, | |
45 not_supported: {n: 43, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'subscribe'}, | |
46 node_has_moved: {n: 44, type: 'modify', error: 'gone', text: true}, | |
47 node_does_not_exist: {n: 45, type: 'cancel', error: 'item-not-found'}, | |
48 configuration_required: {n: 48, type: 'modify', error: 'not-acceptable', reason: 'configuration-required'}, | |
49 }, | |
50 unsubscribe: { | |
51 no_subscription_id: {n: 53, type: 'modify', error: 'bad-request', reason: 'subid-required'}, | |
52 no_such_subscriber: {n: 54, type: 'cancel', error: 'unexpected-request', reason: 'not-subscribed'}, | |
53 insufficient_privileges: {n: 55, type: 'auth', error: 'forbidden'}, | |
54 node_does_not_exist: {n: 56, type: 'cancel', error: 'item-not-found'}, | |
55 bad_subscription_id: {n: 57, type: 'modify', error: 'not-acceptable', reason: 'invalid-subid'}, | |
56 }, | |
57 configure: { | |
58 insufficient_privileges: {n: 61, type: 'auth', error: 'forbidden'}, | |
59 no_such_subscriber: {n: 62, type: 'modify', error: 'unexpected-request', reason: 'not-subscribed'}, | |
60 subscriber_jid_required: {n: 63, type: 'modify', error: 'bad-request', reason: 'jid-required'}, | |
61 subscription_id_required: {n: 64, type: 'modify', error: 'bad-request', reason: 'subid-required'}, | |
62 invalid_subscription_id: {n: 65, type: 'modify', error: 'not-acceptable', reason: 'invalid-subid'}, | |
63 subscription_options_not_supported: {n: 66, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'subscription-options'}, | |
64 node_does_not_exist: {n: 67, type: 'cancel', error: 'item-not-found'}, | |
65 form_processing_failure: {n: 70, type: 'modify', error: 'bad-request', reason: 'invalid-options'}, | |
66 }, | |
67 default_options: { | |
68 node_configuration_not_supported: {n: 76, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'subscription-options'}, | |
69 default_subscription_configuration_retrieval_not_supported: {n: 77, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'retrieve-default-sub'}, | |
70 }, | |
71 retrieve: { | |
72 subscription_id_required: {n: 87, type: 'modify', error: 'bad-request', reason: 'subid-required'}, | |
73 invalid_subscription_id: {n: 88, type: 'modify', error: 'not-acceptable', reason: 'invalid-subid xmlns'}, | |
74 entity_not_subscribed: {n: 89, type: 'auth', error: 'not-authorized', reason: 'not-subscribed'}, | |
75 persistent_items_not_supported: {n: 90, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'persistent-items'}, | |
76 item_retrieval_not_supported: {n: 91, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'retrieve-items'}, | |
77 presence_subscription_required: {n: 92, type: 'auth', error: 'not-authorized', reason: 'presence-subscription-required'}, | |
78 not_in_roster_group: {n: 93, type: 'auth', error: 'not-authorized', reason: 'not-in-roster-group'}, | |
79 not_on_whitelist: {n: 94, type: 'cancel', error: 'not-allowed', reason: 'closed-node'}, | |
80 payment_required: {n: 95, type: 'auth', error: 'payment-required'}, | |
81 blocked: {n: 96, type: 'auth', error: 'forbidden'}, | |
82 node_does_not_exist: {n: 97, type: 'cancel', error: 'item-not-found'}, | |
83 }, | |
84 }; | |
85 | |
86 errors.pub = { | |
87 publish: { | |
88 insufficient_privileges: {n: 105, type: 'auth', error: 'forbidden'}, | |
89 item_publication_not_supported: {n: 106, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'publish'}, | |
90 node_does_not_exist: {n: 107, type: 'cancel', error: 'item-not-found'}, | |
91 payload_too_big: {n: 108, type: 'modify', error: 'not-acceptable', reason: 'payload-too-big'}, | |
92 bad_payload: {n: 109, type: 'modify', error: 'bad-request', reason: 'invalid-payload'}, | |
93 }, | |
94 configuration: { | |
95 no_item: {n: 110, type: 'modify', error: 'bad-request', reason: 'item-required'}, | |
96 no_payload: {n: 111, type: 'modify', error: 'bad-request', reason: 'payload-required'}, | |
97 transient_item: {n: 112, type: 'modify', error: 'bad-request', reason: 'item-forbidden'}, | |
98 precondition: {n: 113, type: 'modify', error: 'conflict', reason: 'precondition-not-met'}, | |
99 | |
100 }, | |
101 retract: { | |
102 insufficient_privileges: {n: 118, type: 'auth', error: 'forbidden'}, | |
103 node_does_not_exist: {n: 119, type: 'cancel', error: 'item-not-found'}, | |
104 nodeid_required: {n: 120, type: 'modify', error: 'bad-request', reason: 'nodeid-required'}, | |
105 item_or_itemid_required: {n: 121, type: 'modify', error: 'bad-request', reason: 'item-required'}, | |
106 persistent_items_not_supported: {n: 122, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'persistent-items'}, | |
107 item_deletion_not_supported: {n: 123, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'delete-items'}, | |
108 }, | |
109 }; | |
110 | |
111 errors.owner = { | |
112 create: { | |
113 node_creation_not_supported: {n: 125, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'create-nodes'}, | |
114 service_requires_registration: {n: 126, type: 'auth', error: 'registration-required'}, | |
115 prohibited: {n: 127, type: 'auth', error: 'forbidden'}, | |
116 nodeid_already_exists: {n: 128, type: 'cancel', error: 'conflict'}, | |
117 instant_nodes_not_supported: {n: 129, type: 'modify', error: 'not-acceptable', reason: 'nodeid-required'}, | |
118 specified_access_model_not_supported: {n: 135, type: 'modify', error: 'not-acceptable', reason: 'unsupported-access-model'}, | |
119 }, | |
120 configure: { | |
121 node_configuration_not_supported: {n: 140, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'config-node'}, | |
122 insufficient_privileges: {n: 141, type: 'auth', error: 'forbidden'}, | |
123 nodeid_required: {n: 142, type: 'modify', error: 'bad-request', reason: 'nodeid-required'}, | |
124 no_configuration_options: {n: 143, type: 'cancel', error: 'not-allowed'}, | |
125 node_does_not_exist: {n: 144, type: 'cancel', error: 'item-not-found'}, | |
126 form_processing_failure: {n: 148, type: 'modify', error: 'not-acceptable'}, | |
127 }, | |
128 default_options: { | |
129 node_configuration_not_supported: {n: 153, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'config-node'}, | |
130 default_node_configuration_retrieval_not_supported: {n: 154, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'retrieve-default'}, | |
131 }, | |
132 delete_node: { | |
133 insufficient_privileges: {n: 159, type: 'auth', error: 'forbidden'}, | |
134 node_does_not_exist: {n: 160, type: 'cancel', error: 'item-not-found'}, | |
135 }, | |
136 purge: { | |
137 node_purging_not_supported: {n: 164, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'purge-nodes'}, | |
138 insufficient_privileges: {n: 165, type: 'auth', error: 'forbidden'}, | |
139 node_does_not_persist_items: {n: 166, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'persistent-items'}, | |
140 node_does_not_exist: {n: 167, type: 'cancel', error: 'item-not-found'}, | |
141 }, | |
142 //manage_subscription_requests: {}, | |
143 pending_subscription_requests: { | |
144 ad_hoc_commands_not_supported: {n: 176, type: 'cancel', error: 'service-unavailable'}, | |
145 get_pending_not_supported: {n: 177, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'get-pending'}, | |
146 insufficient_privileges: {n: 178, type: 'auth', error: 'forbidden'}, | |
147 node_does_not_exist: {n: 179, type: 'cancel', error: 'item-not-found'}, | |
148 }, | |
149 manage_subscriptions: { | |
150 not_supported: {n: 184, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'manage-subscriptions'}, | |
151 retrieve_list: { | |
152 entity_is_not_an_owner: {n: 185, type: 'auth', error: 'forbidden'}, | |
153 node_does_not_exist: {n: 186, type: 'cancel', error: 'item-not-found'}, | |
154 }, | |
155 modify: { | |
156 entity_is_not_an_owner: {n: 190, type: 'auth', error: 'forbidden'}, | |
157 node_does_not_exist: {n: 191, type: 'cancel', error: 'item-not-found'}, | |
158 multiple_simultaneous_modifications: {n: 193, type: 'modify', error: 'not-acceptable'}, | |
159 }, | |
160 }, | |
161 manage_affiliations: { | |
162 not_supported: {n: 197, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'modify-affiliations'}, | |
163 retrieve_list: { | |
164 entity_is_not_an_owner: {n: 198, type: 'auth', error: 'forbidden'}, | |
165 node_does_not_exist: {n: 199, type: 'cancel', error: 'item-not-found'}, | |
166 }, | |
167 modify: { | |
168 requested_affiliation_not_supported: { | |
169 publisher: {n: 203, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'publisher-affiliation'}, | |
170 'publish-only': {n: 203, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'publish-only-affiliation'}, | |
171 member: {n: 203, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'member-affiliation'}, | |
172 outcast: {n: 203, type: 'cancel', error: 'feature-not-implemented', reason: 'unsupported', feature: 'outcast-affiliation'}, | |
173 }, | |
174 entity_is_not_an_owner: {n: 204, type: 'auth', error: 'forbidden'}, | |
175 node_does_not_exist: {n: 205, type: 'cancel', error: 'item-not-found'}, | |
176 multiple_simultaneous_modifications: {n: 207, type: 'modify', error: 'not-acceptable'}, | |
177 }, | |
178 }, | |
179 }; | |
180 | |
40
741110cdcfcf
Avoid exposing unneeded object.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
23
diff
changeset
|
181 var reverse = {}; |
0 | 182 |
40
741110cdcfcf
Avoid exposing unneeded object.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
23
diff
changeset
|
183 (function reverseError(o) { |
0 | 184 for (var i in o) { |
185 if (i == 'reverse' || typeof (o[i]) == 'number'); | |
186 else if (!o[i].n) | |
187 reverseError(o[i]); | |
188 else { | |
189 var k = {}; | |
190 for (var j in o[i]) { | |
191 if (j != 'n') | |
192 k[j] = o[i][j]; | |
193 } | |
40
741110cdcfcf
Avoid exposing unneeded object.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
23
diff
changeset
|
194 reverse[o[i].n] = k; |
0 | 195 } |
196 } | |
40
741110cdcfcf
Avoid exposing unneeded object.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
23
diff
changeset
|
197 })(errors); |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
198 |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
199 exports.makeError = function(response, errorNumber, payload) { |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
200 response.attrs.type = 'error'; |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
201 if (payload) |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
202 response.cnode(payload); |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
203 |
40
741110cdcfcf
Avoid exposing unneeded object.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
23
diff
changeset
|
204 var e = reverse[errorNumber]; |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
205 |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
206 var Element = require('ltx').Element; |
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
207 var error = new Element('error', {type: e.type}); |
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
208 error.c(e.error, {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'}).up(); |
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
209 response.cnode(error); |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
210 |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
211 if (e.reason) { |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
212 if (e.feature) |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
213 error.c(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors', feature: e.feature}).up(); |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
214 else |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
215 error.c(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors'}).up(); |
23
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
216 } |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
217 |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
218 return response; |
5fc4ee90c1bc
A lot of refactorization. First attempt to modularize the server.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
0
diff
changeset
|
219 } |