|
2 | 2 |
|
3 | 3 | from botocore.exceptions import NoCredentialsError |
4 | 4 |
|
| 5 | +# Try to import spine error classes. If successful, we are on spine and should use wrapper classes. |
| 6 | +on_spine = False |
| 7 | +try: |
| 8 | + # from spinecore.prescriptions.common.errors.errorbaseprescriptionsearch \ |
| 9 | + # import ErrorBasePrescSearch # pyright: ignore[reportMissingImports] |
| 10 | + from spinecore.common.aws.awscommon import ( # pyright: ignore[reportMissingImports] |
| 11 | + NoCredentialsErrorWithRetry, |
| 12 | + ) |
| 13 | + from spinecore.common.errors import ( # pyright: ignore[reportMissingImports] |
| 14 | + SpineBusinessError, |
| 15 | + SpineSystemError, |
| 16 | + ) |
5 | 17 |
|
6 | | -class EpsNoCredentialsErrorWithRetry(NoCredentialsError): |
7 | | - """ |
8 | | - Extends NoCredentialsError to provide information about retry attempts. |
9 | | - To be caught in Spine application code and re-raised as NoCredentialsErrorWithRetry. |
10 | | - """ |
11 | | - |
12 | | - fmt = "Unable to locate credentials after {attempts} attempts" |
13 | | - |
14 | | - |
15 | | -class EpsSystemError(Exception): |
16 | | - """ |
17 | | - Exception to be raised if an unexpected system error occurs. |
18 | | - To be caught in Spine application code and re-raised as SpineSystemError. |
19 | | - """ |
20 | | - |
21 | | - MESSAGE_FAILURE = "messageFailure" |
22 | | - DEVELOPMENT_FAILURE = "developmentFailure" |
23 | | - SYSTEM_FAILURE = "systemFailure" |
24 | | - IMMEDIATE_REQUEUE = "immediateRequeue" |
25 | | - RETRY_EXPIRED = "retryExpired" |
26 | | - PUBLISHER_HANDLES_REQUEUE = "publisherHandlesRequeue" |
27 | | - UNRELIABLE_MESSAGE = "unreliableMessage" |
28 | | - |
29 | | - def __init__(self, errorTopic, *args): # noqa: B042 |
30 | | - """ |
31 | | - errorTopic is the topic to be used when writing the WDO to the error exchange |
32 | | - """ |
33 | | - super(EpsSystemError, self).__init__(*args) |
34 | | - self.errorTopic = errorTopic |
35 | | - |
36 | | - |
37 | | -class EpsBusinessError(Exception): |
38 | | - """ |
39 | | - Exception to be raised by a message worker if an expected error condition is hit, |
40 | | - one that is expected to cause a HL7 error response with a set errorCode. |
41 | | - To be caught in Spine application code and re-raised as SpineBusinessError. |
42 | | - """ |
43 | | - |
44 | | - def __init__(self, errorCode, suppInfo=None, messageId=None): # noqa: B042 |
45 | | - super(EpsBusinessError, self).__init__() |
46 | | - self.errorCode = errorCode |
47 | | - self.supplementaryInformation = suppInfo |
48 | | - self.messageId = messageId |
49 | | - |
50 | | - def __str__(self): |
51 | | - if self.supplementaryInformation: |
52 | | - return "{} {}".format(self.errorCode, self.supplementaryInformation) |
53 | | - return str(self.errorCode) |
54 | | - |
55 | | - |
56 | | -class EpsErrorBase(Enum): |
57 | | - """ |
58 | | - To be used in Spine application code to remap to ErrorBases. |
59 | | - """ |
60 | | - |
61 | | - INVALID_LINE_STATE_TRANSITION = 1 |
62 | | - ITEM_NOT_FOUND = 2 |
63 | | - MAX_REPEAT_MISMATCH = 3 |
64 | | - NOT_CANCELLED_EXPIRED = 4 |
65 | | - NOT_CANCELLED_CANCELLED = 5 |
66 | | - NOT_CANCELLED_NOT_DISPENSED = 6 |
67 | | - NOT_CANCELLED_DISPENSED = 7 |
68 | | - NOT_CANCELLED_WITH_DISPENSER = 8 |
69 | | - NOT_CANCELLED_WITH_DISPENSER_ACTIVE = 9 |
70 | | - PRESCRIPTION_NOT_FOUND = 10 |
| 18 | + # from spinecore.prescriptions.common.errors.errorbase1634 \ |
| 19 | + # import ErrorBase1634 # pyright: ignore[reportMissingImports] |
| 20 | + from spinecore.prescriptions.common.errors.errorbase1719 import ( # pyright: ignore[reportMissingImports] |
| 21 | + ErrorBase1719, |
| 22 | + ) |
| 23 | + from spinecore.prescriptions.common.errors.errorbase1722 import ( # pyright: ignore[reportMissingImports] |
| 24 | + ErrorBase1722, |
| 25 | + ) |
| 26 | + |
| 27 | + on_spine = True |
| 28 | +except ImportError: |
| 29 | + pass |
| 30 | + |
| 31 | + |
| 32 | +if on_spine: |
| 33 | + |
| 34 | + class EpsNoCredentialsErrorWithRetry: |
| 35 | + """ |
| 36 | + Wrapper for NoCredentialsErrorWithRetry |
| 37 | + """ |
| 38 | + |
| 39 | + def __init__(self, *args): |
| 40 | + raise NoCredentialsErrorWithRetry(*args) |
| 41 | + |
| 42 | + class EpsSystemError: |
| 43 | + """ |
| 44 | + Wrapper for SpineSystemError |
| 45 | + """ |
| 46 | + |
| 47 | + def __init__(self, *args): |
| 48 | + raise SpineSystemError(*args) |
| 49 | + |
| 50 | + class EpsBusinessError: |
| 51 | + """ |
| 52 | + Wrapper for SpineBusinessError |
| 53 | + """ |
| 54 | + |
| 55 | + def __init__(self, *args): |
| 56 | + raise SpineBusinessError(*args) |
| 57 | + |
| 58 | + class EpsErrorBase: |
| 59 | + """ |
| 60 | + Wrapper for ErrorBases |
| 61 | + """ |
| 62 | + |
| 63 | + MISSING_ISSUE = ErrorBase1722.PRESCRIPTION_NOT_FOUND |
| 64 | + ITEM_NOT_FOUND = ErrorBase1722.ITEM_NOT_FOUND |
| 65 | + INVALID_LINE_STATE_TRANSITION = ErrorBase1722.INVALID_LINE_STATE_TRANSITION |
| 66 | + MAX_REPEAT_MISMATCH = ErrorBase1722.MAX_REPEAT_MISMATCH |
| 67 | + NOT_CANCELLED_EXPIRED = ErrorBase1719.NOT_CANCELLED_EXPIRED |
| 68 | + NOT_CANCELLED_CANCELLED = ErrorBase1719.NOT_CANCELLED_CANCELLED |
| 69 | + NOT_CANCELLED_NOT_DISPENSED = ErrorBase1719.NOT_CANCELLED_NOT_DISPENSED |
| 70 | + NOT_CANCELLED_DISPENSED = ErrorBase1719.NOT_CANCELLED_DISPENSED |
| 71 | + NOT_CANCELLED_WITH_DISPENSER = ErrorBase1719.NOT_CANCELLED_WITH_DISPENSER |
| 72 | + NOT_CANCELLED_WITH_DISPENSER_ACTIVE = ErrorBase1719.NOT_CANCELLED_WITH_DISPENSER_ACTIVE |
| 73 | + PRESCRIPTION_NOT_FOUND = ErrorBase1719.PRESCRIPTION_NOT_FOUND |
| 74 | + |
| 75 | +else: |
| 76 | + |
| 77 | + class EpsNoCredentialsErrorWithRetry(NoCredentialsError): |
| 78 | + """ |
| 79 | + Extends NoCredentialsError to provide information about retry attempts. |
| 80 | + """ |
| 81 | + |
| 82 | + fmt = "Unable to locate credentials after {attempts} attempts" |
| 83 | + |
| 84 | + class EpsSystemError(Exception): |
| 85 | + """ |
| 86 | + Exception to be raised if an unexpected system error occurs. |
| 87 | + """ |
| 88 | + |
| 89 | + MESSAGE_FAILURE = "messageFailure" |
| 90 | + DEVELOPMENT_FAILURE = "developmentFailure" |
| 91 | + SYSTEM_FAILURE = "systemFailure" |
| 92 | + IMMEDIATE_REQUEUE = "immediateRequeue" |
| 93 | + RETRY_EXPIRED = "retryExpired" |
| 94 | + PUBLISHER_HANDLES_REQUEUE = "publisherHandlesRequeue" |
| 95 | + UNRELIABLE_MESSAGE = "unreliableMessage" |
| 96 | + |
| 97 | + def __init__(self, error_topic, *args): # noqa: B042 |
| 98 | + """ |
| 99 | + error_topic is the topic to be used when writing the WDO to the error exchange |
| 100 | + """ |
| 101 | + super(EpsSystemError, self).__init__(*args) |
| 102 | + self.error_topic = error_topic |
| 103 | + |
| 104 | + class EpsBusinessError(Exception): |
| 105 | + """ |
| 106 | + Exception to be raised by a message worker if an expected error condition is hit, |
| 107 | + one that is expected to cause a HL7 error response with a set errorCode. |
| 108 | + """ |
| 109 | + |
| 110 | + def __init__(self, error_code, supp_info=None, message_id=None): # noqa: B042 |
| 111 | + super(EpsBusinessError, self).__init__() |
| 112 | + self.error_code = error_code |
| 113 | + self.supplementary_information = supp_info |
| 114 | + self.message_id = message_id |
| 115 | + |
| 116 | + def __str__(self): |
| 117 | + if self.supplementary_information: |
| 118 | + return "{} {}".format(self.error_code, self.supplementary_information) |
| 119 | + return str(self.error_code) |
| 120 | + |
| 121 | + class EpsErrorBase(Enum): |
| 122 | + """ |
| 123 | + To be used in Spine application code to remap to ErrorBases. |
| 124 | + """ |
| 125 | + |
| 126 | + INVALID_LINE_STATE_TRANSITION = 1 |
| 127 | + ITEM_NOT_FOUND = 2 |
| 128 | + MAX_REPEAT_MISMATCH = 3 |
| 129 | + NOT_CANCELLED_EXPIRED = 4 |
| 130 | + NOT_CANCELLED_CANCELLED = 5 |
| 131 | + NOT_CANCELLED_NOT_DISPENSED = 6 |
| 132 | + NOT_CANCELLED_DISPENSED = 7 |
| 133 | + NOT_CANCELLED_WITH_DISPENSER = 8 |
| 134 | + NOT_CANCELLED_WITH_DISPENSER_ACTIVE = 9 |
| 135 | + PRESCRIPTION_NOT_FOUND = 10 |
| 136 | + MISSING_ISSUE = 11 |
0 commit comments