Commits

Robert Brewer  committed 354564e

Fix for #359 (custom errors have no args attribute).

  • Participants
  • Parent commits 3ad37ff

Comments (0)

Files changed (2)

File cherrypy/_cperror.py

         request.browserUrl = request.base + path
         if request.queryString:
             request.browserUrl += '?' + request.queryString
+        
+        Exception.__init__(self, path, params)
 
 
 
                 raise ValueError("status must be between 300 and 399.")
         
         self.status = status
+        Exception.__init__(self, abs_urls, status)
     
     def set_response(self):
         import cherrypy
         if status < 400 or status > 599:
             raise ValueError("status must be between 400 and 599.")
         self.message = message
+        Error.__init__(self, status, message)
     
     def set_response(self):
         import cherrypy
         
         if cherrypy.response.headerMap.has_key("Content-Encoding"):
             del cherrypy.response.headerMap['Content-Encoding']
-    
-    def __str__(self):
-        import cherrypy
-        return "%s: %s" % (self.status, self.message or "")
 
 
 class NotFound(HTTPError):

File cherrypy/test/test_core.py

 
 class Redirect(Test):
     
-    def _cpOnError(self):
-        raise cherrypy.HTTPRedirect("/errpage")
-    
-    def error(self):
-        raise NameError()
+    class Error:
+        def _cpOnError(self):
+            raise cherrypy.HTTPRedirect("/errpage")
+        
+        def index(self):
+            raise NameError()
+        index.exposed = True
+    error = Error()
     
     def index(self):
         return "child"
                                            {"user_id": "fish"})
         else:
             raise cherrypy.InternalRedirect('/image/getImagesByUser')
+    
+    def stringify(self):
+        return str(cherrypy.HTTPRedirect("/"))
 
 
 class Image(Test):
         self.assertStatus('200 OK')
         
         # HTTPRedirect on error
-        self.getPage("/redirect/error")
+        self.getPage("/redirect/error/")
         self.assertStatus('303 See Other')
         self.assertInBody('/errpage')
+        
+        # Make sure str(HTTPRedirect()) works.
+        self.getPage("/redirect/stringify")
+        self.assertStatus('200 OK')
+        self.assertBody("(['http://127.0.0.1:8000/'], 303)")
     
     def testCPFilterList(self):
         self.getPage("/cpfilterlist/")