Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

#!/usr/bin/env python 

 

""" 

@file ion/core/exception.py 

@author Michael Meisinger 

@brief module for exceptions 

""" 

 

import ion.util.ionlog 

log = ion.util.ionlog.getLogger(__name__) 

 

class FatalError(Exception): 

    """ 

    Raise this exception from within a process/service op_ method when 

    things go really wrong for you. This gives you the ability to "fail 

    quickly"; the container will die, and it's monitoring system can take 

    action to start a replacement. 

    """ 

 

# User-defined Exceptions should be derived from Exception 

class IonError(StandardError): 

    pass 

 

    # @todo Some better str output 

 

class ConfigurationError(IonError): 

    pass 

 

class StartupError(IonError): 

    pass 

 

class IllegalStateError(IonError): 

    pass 

 

class ConversationError(IonError): 

    pass 

 

class ConversationTimeoutError(ConversationError): 

    pass 

 

class ConversationUnexpectedError(ConversationError): 

    pass 

 

class ConversationFailureError(ConversationError): 

    pass 

 

class ApplicationError(IonError): 

    """ 

    @Brief An Exception class for use in service business logic which will not result in the service 

    being terminated. Any exception thrown which is not a subclass of Application Error will 

    cause the process to terminate. 

    """ 

 

    def __init__(self, reason, response_code=500): 

        """ 

        @param reason a string explaining the cause of the exception 

        @param response_code is an http style numerical error code. These are defined in the ION Message 

        When this exception is used in RPC messaging, a 400 level code will result in a 

        ReceivedApplicationError in the originating process. A 500 level code will result in a 

        ReceivedContainerError. 

        """ 

 

        # Set up the exception 

        IonError.__init__(self, reason) 

 

        # Set the response code 

        self.response_code = response_code 

 

class ReceivedError(IonError): 

 

    def __init__(self, headers, content): 

            self.msg_headers = headers 

            self.msg_content = content 

            msg = "ERROR received in message" 

            IonError.__init__(self, msg) 

 

class ReceivedContainerError(ReceivedError): 

    """ 

    An exception to throw when a 5XX response code is received during RPC messaging 

    """ 

 

class ReceivedApplicationError(ReceivedError): 

    """ 

    An exception to throw for 4XX response code is received during RPC messaging 

    """ 

 

 

 

#class ReceivedError(IonError): 

# 

#    def __init__(self, *args, **kwargs): 

#        if len(args) == 2 and type(args[0]) is dict and type(args[1]) is dict: 

#            headers = args[0] 

#            content = args[1] 

#            self.msg_headers = headers 

#            self.msg_content = content 

#            msg = content.get('errmsg', "ERROR received in message") 

#            IonError.__init__(self, msg) 

#        else: 

#            IonError.__init__(self, *args, **kwargs)