comparison sat_pubsub/pgsql_storage.py @ 429:0526073ff2ab

pgsql: replaced ValueError by BadRequest: `BadRequest` results in a proper IQ error, while `ValueError` results in an InternalError.
author Goffi <goffi@goffi.org>
date Thu, 10 Dec 2020 10:46:34 +0100
parents 3fce48c0a44d
children 5a0ada3b61ca
comparison
equal deleted inserted replaced
428:34bd55179e22 429:0526073ff2ab
59 from twisted.internet import defer 59 from twisted.internet import defer
60 from twisted.words.protocols.jabber import jid 60 from twisted.words.protocols.jabber import jid
61 from twisted.python import log 61 from twisted.python import log
62 62
63 from wokkel import generic 63 from wokkel import generic
64 from wokkel.pubsub import Subscription 64 from wokkel.pubsub import Subscription, BadRequest
65 65
66 from sat_pubsub import error 66 from sat_pubsub import error
67 from sat_pubsub import iidavoll 67 from sat_pubsub import iidavoll
68 from sat_pubsub import const 68 from sat_pubsub import const
69 from sat_pubsub import container 69 from sat_pubsub import container
172 } 172 }
173 node = CollectionNode(row[0], row[1], configuration, None) 173 node = CollectionNode(row[0], row[1], configuration, None)
174 node.dbpool = self.dbpool 174 node.dbpool = self.dbpool
175 return node 175 return node
176 else: 176 else:
177 raise ValueError("Unknown node type !") 177 raise BadRequest(text="Unknown node type !")
178 178
179 def getNodeById(self, nodeDbId): 179 def getNodeById(self, nodeDbId):
180 """Get node using database ID insted of pubsub identifier 180 """Get node using database ID insted of pubsub identifier
181 181
182 @param nodeDbId(unicode): database ID 182 @param nodeDbId(unicode): database ID
431 return last_items 431 return last_items
432 432
433 def getLastItems(self, entities, nodes, node_accesses, item_accesses, pep): 433 def getLastItems(self, entities, nodes, node_accesses, item_accesses, pep):
434 """get last item for several nodes and entities in a single request""" 434 """get last item for several nodes and entities in a single request"""
435 if not entities or not nodes or not node_accesses or not item_accesses: 435 if not entities or not nodes or not node_accesses or not item_accesses:
436 raise ValueError("entities, nodes and accesses must not be empty") 436 raise BadRequest(text="entities, nodes and accesses must not be empty")
437 if node_accesses != ('open',) or item_accesses != ('open',): 437 if node_accesses != ('open',) or item_accesses != ('open',):
438 raise NotImplementedError('only "open" access model is handled for now') 438 raise NotImplementedError('only "open" access model is handled for now')
439 if not pep: 439 if not pep:
440 raise NotImplementedError("getLastItems is only implemented for PEP at the moment") 440 raise NotImplementedError("getLastItems is only implemented for PEP at the moment")
441 d = self.dbpool.runQuery("""SELECT DISTINCT ON (node_id) pep, node, data::text, items.access_model 441 d = self.dbpool.runQuery("""SELECT DISTINCT ON (node_id) pep, node, data::text, items.access_model