Improve error handling.
This commit is contained in:
parent
ed33aca596
commit
16bd475be2
2 changed files with 58 additions and 33 deletions
|
@ -55,21 +55,26 @@ async def view_pubsub(request: Request):
|
|||
if settings['service']:
|
||||
if settings['include'] in pubsub or not settings['include']:
|
||||
if pubsub and node and item_id:
|
||||
iq = await xmpp.plugin['xep_0060'].get_item(pubsub, node, item_id)
|
||||
link = 'xmpp:{pubsub}?;node={node};item={item}'.format(
|
||||
pubsub=pubsub, node=node, item=item_id)
|
||||
xml_atom = generate_rfc_4287(iq, link)
|
||||
result = append_stylesheet(xml_atom)
|
||||
iq = await get_node_items(pubsub, node)
|
||||
iq = await get_node_item(pubsub, node, item_id)
|
||||
if iq:
|
||||
generate_json(iq, node)
|
||||
link = 'xmpp:{pubsub}?;node={node};item={item}'.format(
|
||||
pubsub=pubsub, node=node, item=item_id)
|
||||
xml_atom = generate_rfc_4287(iq, link)
|
||||
iq = await get_node_items(pubsub, node)
|
||||
if iq:
|
||||
generate_json(iq, node)
|
||||
else:
|
||||
operator = get_configuration('settings')['operator']
|
||||
json_data = [{'title' : 'Timeout Error: Press here to contact the operator.',
|
||||
'link' : 'xmpp:{}?message'.format(operator)}]
|
||||
filename = 'data/{}.json'.format(node)
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(json_data, f, ensure_ascii=False, indent=4)
|
||||
else:
|
||||
operator = get_configuration('settings')['operator']
|
||||
json_data = [{'title' : 'Timeout Error: Press here to contact the operator.',
|
||||
'link' : 'xmpp:{}?message'.format(operator)}]
|
||||
filename = 'data/{}.json'.format(node)
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(json_data, f, ensure_ascii=False, indent=4)
|
||||
text = 'Please check that PubSub node and item are valid and accessible.'
|
||||
xml_atom = error_message(text)
|
||||
result = append_stylesheet(xml_atom)
|
||||
|
||||
# try:
|
||||
# iq = await get_node_items(pubsub, node)
|
||||
# generate_json(iq, node)
|
||||
|
@ -82,13 +87,22 @@ async def view_pubsub(request: Request):
|
|||
# json.dump(json_data, f, ensure_ascii=False, indent=4)
|
||||
elif pubsub and node:
|
||||
iq = await get_node_items(pubsub, node)
|
||||
link = form_a_link(pubsub, node)
|
||||
xml_atom = generate_rfc_4287(iq, link)
|
||||
if iq:
|
||||
link = form_a_link(pubsub, node)
|
||||
xml_atom = generate_rfc_4287(iq, link)
|
||||
else:
|
||||
text = 'Please check that PubSub node is valid and accessible.'
|
||||
xml_atom = error_message(text)
|
||||
result = append_stylesheet(xml_atom)
|
||||
elif pubsub:
|
||||
iq = await xmpp.plugin['xep_0060'].get_nodes(pubsub)
|
||||
link = 'xmpp:{pubsub}'.format(pubsub=pubsub)
|
||||
result = pubsub_to_opml(iq)
|
||||
iq = await get_nodes(pubsub)
|
||||
if iq:
|
||||
link = 'xmpp:{pubsub}'.format(pubsub=pubsub)
|
||||
result = pubsub_to_opml(iq)
|
||||
else:
|
||||
text = 'Please check that PubSub Jabber ID is valid and accessible.'
|
||||
xml_atom = error_message(text)
|
||||
result = append_stylesheet(xml_atom)
|
||||
elif node:
|
||||
text = 'PubSub parameter is missing.'
|
||||
xml_atom = error_message(text)
|
||||
|
@ -130,11 +144,25 @@ def get_configuration(section):
|
|||
return result
|
||||
|
||||
#@timeout(5)
|
||||
async def get_node_item(pubsub, node, item_id):
|
||||
try:
|
||||
iq = await xmpp.plugin['xep_0060'].get_item(pubsub, node, item_id, timeout=5)
|
||||
return iq
|
||||
except (IqError, IqTimeout) as e:
|
||||
print(e)
|
||||
|
||||
async def get_node_items(pubsub, node):
|
||||
try:
|
||||
iq = await xmpp.plugin['xep_0060'].get_items(pubsub, node, timeout=5)
|
||||
return iq
|
||||
except IqTimeout as e:
|
||||
except (IqError, IqTimeout) as e:
|
||||
print(e)
|
||||
|
||||
async def get_nodes(pubsub):
|
||||
try:
|
||||
await xmpp.plugin['xep_0060'].get_nodes(pubsub, timeout=5)
|
||||
return iq
|
||||
except (IqError, IqTimeout) as e:
|
||||
print(e)
|
||||
|
||||
def form_a_link(pubsub, node):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue