durusmail: quixote-users: handling non publisherror exceptions
handling non publisherror exceptions
2005-04-21
2005-04-21
handling non publisherror exceptions
ThomasGüttler
2005-04-21
Am Donnerstag, 21. April 2005 12:20 schrieb Jamie Hillman:
> Hi,
>
> I'm porting a rather large quixote app from an ancient version of
> quixote to 1.2 and i'm having a problem with exception handling.  It
> seems that only PublishErrors are now handled by _q_exception_handler.

Hi,

I overwrite _generate_cgitb_error in my publisher. The HTML of the cgitb is
written to a file and if a special file exists, the cgitb page is returned
(debugging). If the file (... "debug-modarch") does not exist, then the
string value of the exception is displayed in a template.

Maybe this helps you:
   def _generate_cgitb_error(self, request, original_response,
                              exc_type, exc_value, tb):
        import cgi
        import shutil
        from fuelle_template import fuelle_template

        cgitb_error=Publisher._generate_cgitb_error(self, request,
                                                    original_response,
                                                    exc_type, exc_value, tb)

        # Speichere HTML-Traceback. Er enthält mehr Informationen
        # als der Ascii Traceback in der E-Mail
        savedir=os.path.join(self.modarch.home, "log", "exceptions")
        if not os.path.exists(savedir):
            os.makedirs(savedir)
        htmlfile=os.path.join(savedir, "%s-%s-%s.html" % (
            time.strftime("%Y-%m-%d-%H-%M-%S"),
            random.randint(1000, 9999),
            request.environ.get("REMOTE_USER")))
        fd=open(htmlfile, "wt")
        fd.write(cgitb_error)
        fd.close()
        print "Erstellte HTML Traceback in %s" % htmlfile
        if os.path.exists(os.path.join(self.modarch.home,
                                       "log", "debug-modarch")):
            return cgitb_error

        if exc_value:
            # assert mytest, "Fehler: ...."
            text=str(exc_value)
        else:
            # raise("Fehler: ...")
            text=str(exc_type)
        text=cgi.escape(text)
        mydict={}
        mydict["TEXT"]=text
        return fuelle_template(
            self.modarch.modarch_handler.templates["fehler"],
            mydict, request, self.modarch)

 Thomas


--
Thomas Güttler, TBZ-PARIV GmbH, Bernsdorfer Str. 210-212, 09126 Chemnitz
Tel.: 0371/5221217 Fax:  0371/5221216


reply