From 5f051d535ff36955efaedd8a4e51c3914855a3d4 Mon Sep 17 00:00:00 2001
From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de>
Date: Tue, 20 Mar 2018 17:30:26 +0100
Subject: [PATCH] Catch WikiException in creating the connection

/close #186

This is the reason why the errors for #107 were not reported.
Still, this does not fix pushing to MediaWiki, as the problem is on the
wiki side.
---
 tasks.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/tasks.py b/tasks.py
index 1d142ed..b94e8be 100644
--- a/tasks.py
+++ b/tasks.py
@@ -583,17 +583,18 @@ def push_to_wiki(protocol, content, infobox_content, summary):
 
 @celery.task
 def push_to_wiki_async(protocol_id, content, infobox_content, summary):
-    with WikiClient() as wiki_client, app.app_context():
+    with app.app_context():
         protocol = Protocol.query.filter_by(id=protocol_id).first()
         try:
-            wiki_client.edit_page(
-                title=protocol.protocoltype.get_wiki_infobox_title(),
-                content=infobox_content,
-                summary=summary)
-            wiki_client.edit_page(
-                title=protocol.get_wiki_title(),
-                content=content,
-                summary=summary)
+            with WikiClient() as wiki_client:
+                wiki_client.edit_page(
+                    title=protocol.protocoltype.get_wiki_infobox_title(),
+                    content=infobox_content,
+                    summary=summary)
+                wiki_client.edit_page(
+                    title=protocol.get_wiki_title(),
+                    content=content,
+                    summary=summary)
         except WikiException as exc:
             return _make_error(
                 protocol, "Pushing to Wiki", "Pushing to Wiki failed.",
-- 
GitLab