-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.py
41 lines (31 loc) · 1.38 KB
/
support.py
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
from ojp import Ojp, Ojpresponse, ServiceDelivery, ServiceDeliveryStructure, OtherError
from xsdata.models.datatype import XmlDateTime
import datetime
# err_str = "" #global error string
# define an error response immediatly and make sure the program can send it back (ignores all warnings that were before).
def error_response(error_text:str):
return Ojp(ojpresponse=
Ojpresponse(service_delivery=
ServiceDelivery(response_timestamp=XmlDateTime.from_datetime(datetime.datetime.utcnow()),
producer_ref="OJP2NOVA",
error_condition=ServiceDeliveryStructure.ErrorCondition(other_error=OtherError(error_text)))))
# storing warnings to be sent with the answer
#def add_error(error_text:str):
# global err_str
# err_str=err_str+error_text
# return
# include accumulated warnings into the response. Status not affected (so should be warnings)
# def add_error_response(sd:ServiceDeliveryStructure):
# global err_str
# if err_str=="":
# return sd
# sd.ErrorCondition(other_error=OtherError(err_str))
# return sd
# raising an error and sending it back. Does not add values from err_str
class OJPError(Exception):
# Constructor or Initializer
def __init__(self, value):
self.value = value
# __str__ is to print() the value
def __str__(self):
return (repr(self.value))