Fixed uncaught exception in RAL.
authorŁukasz Rekucki <lrekucki@gmail.com>
Mon, 28 Sep 2009 16:43:05 +0000 (18:43 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Mon, 28 Sep 2009 16:43:05 +0000 (18:43 +0200)
apps/api/handlers/library_handlers.py
apps/api/response.py
apps/api/utils.py
lib/wlrepo/mercurial_backend/library.py

index 5696cc9..591d4e9 100644 (file)
@@ -175,6 +175,7 @@ class DocumentHandler(BaseHandler):
             'html_url': reverse('dochtml_view', args=[udoc.id,udoc.revision]),
             'text_url': reverse('doctext_view', args=[udoc.id,udoc.revision]),
             'dc_url': reverse('docdc_view', args=[udoc.id,udoc.revision]),
             'html_url': reverse('dochtml_view', args=[udoc.id,udoc.revision]),
             'text_url': reverse('doctext_view', args=[udoc.id,udoc.revision]),
             'dc_url': reverse('docdc_view', args=[udoc.id,udoc.revision]),
+            #'gallery_url': reverse('docdc_view', args=[udoc.id,udoc.revision]),
             'user_revision': udoc.revision,
             'public_revision': doc.revision,            
         }       
             'user_revision': udoc.revision,
             'public_revision': doc.revision,            
         }       
@@ -204,9 +205,6 @@ class DocumentHTMLHandler(BaseHandler):
         except RevisionNotFound:
             return response.EntityNotFound().django_response()
 
         except RevisionNotFound:
             return response.EntityNotFound().django_response()
 
-
-
-
 #
 # Document Text View
 #
 #
 # Document Text View
 #
@@ -214,6 +212,7 @@ class DocumentHTMLHandler(BaseHandler):
 XINCLUDE_REGEXP = r"""<(?:\w+:)?include\s+[^>]*?href=("|')wlrepo://(?P<link>[^\1]+?)\1\s*[^>]*?>"""
 #
 #
 XINCLUDE_REGEXP = r"""<(?:\w+:)?include\s+[^>]*?href=("|')wlrepo://(?P<link>[^\1]+?)\1\s*[^>]*?>"""
 #
 #
+#
 class DocumentTextHandler(BaseHandler):
     allowed_methods = ('GET', 'PUT')
 
 class DocumentTextHandler(BaseHandler):
     allowed_methods = ('GET', 'PUT')
 
@@ -296,7 +295,9 @@ class DocumentTextHandler(BaseHandler):
                 if ndoc: lib._rollback()
                 raise e        
         except RevisionNotFound, e:
                 if ndoc: lib._rollback()
                 raise e        
         except RevisionNotFound, e:
-            return response.EntityNotFound().django_response(e)
+            return response.EntityNotFound(mimetype="text/plain").\
+                django_response(e.message)
+
 
 #
 # Dublin Core handlers
 
 #
 # Dublin Core handlers
@@ -352,16 +353,15 @@ class DocumentDublinCoreHandler(BaseHandler):
                     "document": ndoc.id,
                     "subview": "dc",
                     "previous_revision": current.revision,
                     "document": ndoc.id,
                     "subview": "dc",
                     "previous_revision": current.revision,
-                    "updated_revision": ndoc.revision
+                    "updated_revision": ndoc.revision,
+                    "url": reverse("docdc_view", args=[ndoc.id, ndoc.revision])
                 }
             except Exception, e:
                 }
             except Exception, e:
-                lib._rollback()
+                if ndoc: lib._rollback()
                 raise e
         except RevisionNotFound:
             return response.EntityNotFound().django_response()
 
                 raise e
         except RevisionNotFound:
             return response.EntityNotFound().django_response()
 
-
-
 class MergeHandler(BaseHandler):
     allowed_methods = ('POST',)
 
 class MergeHandler(BaseHandler):
     allowed_methods = ('POST',)
 
index a094f9c..0d38a3a 100644 (file)
@@ -22,8 +22,8 @@ class ResponseObject(object):
         elif self._mime == MIME_JSON:
             data = json.dumps(body, default=lambda o: repr(o) )
         else:
         elif self._mime == MIME_JSON:
             data = json.dumps(body, default=lambda o: repr(o) )
         else:
-            data = u"%s\n%s" % (self.MESSAGE, unicode(body))
-            data = data.encode('utf-8')
+            data = u"%s\n%s" % (self.MESSAGE, unicode(body))
+            data = unicode(body).encode('utf-8')
             
         return HttpResponse(content=data, status=self._code, \
                 content_type=self._mime+'; charset=utf-8' )        
             
         return HttpResponse(content=data, status=self._code, \
                 content_type=self._mime+'; charset=utf-8' )        
index a52e555..93e54be 100644 (file)
@@ -53,8 +53,5 @@ def hglibrary(func):
         l = MercurialLibrary(settings.REPOSITORY_PATH)
         kwargs['lib'] = l
         return func(self, *args, **kwargs)
         l = MercurialLibrary(settings.REPOSITORY_PATH)
         kwargs['lib'] = l
         return func(self, *args, **kwargs)
-    return decorated
-    
-            
-        
+    return decorated                   
 
 
index 7a33bf3..648ebe9 100644 (file)
@@ -97,11 +97,14 @@ class MercurialLibrary(wlrepo.Library):
 
     def get_revision(self, revid):
         revid = self._sanitize_string(revid)
 
     def get_revision(self, revid):
         revid = self._sanitize_string(revid)
-        
-        ctx = self._changectx(revid)
+
+        try:
+            ctx = self._changectx(revid)
+        except mercurial.error.RepoError, e:
+            raise wlrepo.RevisionNotFound(revid)
 
         if ctx is None:
 
         if ctx is None:
-            raise RevisionNotFound(revid)
+            raise wlrepo.RevisionNotFound(revid)
 
         if self._revcache.has_key(ctx):
             return self._revcache[ctx]
 
         if self._revcache.has_key(ctx):
             return self._revcache[ctx]
@@ -123,7 +126,7 @@ class MercurialLibrary(wlrepo.Library):
         try:
             self._hgrepo[revid]
             return True
         try:
             self._hgrepo[revid]
             return True
-        except error.RepoError:
+        except mercurial.error.RepoError:
             return False
 
     def document_create(self, docid):
             return False
 
     def document_create(self, docid):