source: TI03-DataExtractor/branches/old_stuff/abstractPWSC/errorHandler.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/abstractPWSC/errorHandler.py@793
Revision 793, 1.8 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6errorHandler.py
7===============
8
9Holds Error handling class.
10
11"""
12
13# import standard library modules
14import os, sys
15import smtplib
16
17# import local modules
18from clientConfig import *
19from common import *
20
21class ErrorHandler:
22    def __init__(self, msg):
23        self.msg=msg
24        self._displayError()
25    def _displayError(self):
26        raise "ERROR: "+self.msg
27
28class qErrorHandler:
29    """
30    Used to handle errors sensibly by reporting on-screen
31    to the user and sending a message to the administrator.
32    """
33   
34    def __init__(self, msg, request_id=None, user=None):
35        """
36        Method to build the instance variables required in the class and
37        calls the appropriate internal methods. Used to handle errors by calling displayError and
38        MailAdministrator class.
39        """
40
41        # First report the error to the user
42        self.displayError(msg, noheader)
43
44        stdout=sys.stdout
45        sys.stdout=RedirectStdout()
46
47        # Mail the administrator if switched on (1)       
48        if ADMIN_NOTIFICATION==1:
49            mailer=MailAdministrator("Error generated by %s: %s, %s" % (PACKAGE_NAME, user, request_id))
50            appendee="""
51        User: %s
52        Request ID: %s
53        """ % (user, request_id)
54            mailer.sendMail(msg+appendee)
55
56        sys.stdout=stdout
57        sys.exit()
58
59   
60    def generateError(self, msg):
61        """
62        generateError method - used to create a clean error for the client.
63        """
64        errorMessage="""<P>An error has occurred with this application. The error message received is:
65
66%s
67
68The administrator has been informed of this error and will look into it.""" % msg
69        return errorMessage
70   
71
72
73
74
Note: See TracBrowser for help on using the repository browser.