From 64ac265fe79c31a470ffa571b56b86ff67c9072e Mon Sep 17 00:00:00 2001
From: Ivan Tyagov <ivan@nexedi.com>
Date: Fri, 15 Jun 2007 11:56:06 +0000
Subject: [PATCH] Handle possible exception in document ingestion. Inform user
 with nice message.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14835 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../WebSite_contributeContent.xml             | 37 ++++++++++++++++---
 bt5/erp5_web/bt/revision                      |  2 +-
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_contributeContent.xml b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_contributeContent.xml
index dd083a823a..8fa62eb676 100644
--- a/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_contributeContent.xml
+++ b/bt5/erp5_web/SkinTemplateItem/portal_skins/erp5_web_widget_library/WebSite_contributeContent.xml
@@ -74,6 +74,11 @@
 \n
   **kw -- remaining params passed to the constructor\n
 """\n
+\n
+from Products.ERP5.Document.Document import ConversionError\n
+from xmlrpclib import Fault\n
+from socket import error as SocketError\n
+\n
 # Do some processing of parameters cause we do not use ERP5 Form here\n
 if contribute_classification:\n
   kw[\'classification\'] = contribute_classification\n
@@ -93,13 +98,25 @@ kw[\'discover_metadata\'] = 0 \n
 editable_mode = 1\n
 file_name = getattr(contribute_file, \'filename\', None)\n
 # try to ingest file\n
+failure = 0\n
 try:\n
   new_content = context.portal_contributions.newContent(**kw)\n
   merged_content = new_content.discoverMetadata(file_name=file_name)\n
-except Exception, e:\n
+except ConversionError, Fault:\n
   # there are errors during ingestion content\n
-  msg = \'There was a problem during ingestion: ${exception}. Please try again later.\'\n
-  msg = context.Base_translateString(msg, mapping=dict(exception=str(e)))\n
+  failure = 1\n
+  msg = \'Sorry, there was a problem during conversion of your document.\'\n
+except SocketError:\n
+  # conversion server is down\n
+  failure = 1\n
+  msg = \'Sorry, the conversion server is down. Please try again later.\'\n
+except (TypeError, KeyError, AttributeError):\n
+  # there\'s an unknow  error occured\n
+  failure = 1\n
+  msg = \'Sorry, unknow error occured.\'\n
+  \n
+if failure:\n
+  msg = context.Base_translateString(msg)\n
   return context.Base_redirect(\'WebSite_viewAsSCALE\', \n
                                 keep_items=dict(portal_status_message=msg,\n
                                                 editable_mode=0))\n
@@ -161,21 +178,29 @@ return target.Base_redirect(\'view\', \n
                             <string>contribute_source_project</string>
                             <string>contribute_portal_type</string>
                             <string>kw</string>
+                            <string>Products.ERP5.Document.Document</string>
+                            <string>ConversionError</string>
+                            <string>xmlrpclib</string>
+                            <string>Fault</string>
+                            <string>socket</string>
+                            <string>error</string>
+                            <string>SocketError</string>
                             <string>_write_</string>
                             <string>None</string>
                             <string>editable_mode</string>
                             <string>getattr</string>
                             <string>file_name</string>
+                            <string>failure</string>
                             <string>_apply_</string>
                             <string>_getattr_</string>
                             <string>context</string>
                             <string>new_content</string>
                             <string>merged_content</string>
-                            <string>Exception</string>
-                            <string>e</string>
                             <string>msg</string>
+                            <string>TypeError</string>
+                            <string>KeyError</string>
+                            <string>AttributeError</string>
                             <string>dict</string>
-                            <string>str</string>
                             <string>target</string>
                           </tuple>
                         </value>
diff --git a/bt5/erp5_web/bt/revision b/bt5/erp5_web/bt/revision
index e9059e02c3..4a722e9c7f 100644
--- a/bt5/erp5_web/bt/revision
+++ b/bt5/erp5_web/bt/revision
@@ -1 +1 @@
-549
\ No newline at end of file
+552
\ No newline at end of file
-- 
2.30.9