Improved error handling

This commit is contained in:
Mark Qvist 2022-03-25 20:25:00 +01:00
parent 704930f91a
commit 38cc471eaf

View file

@ -405,11 +405,7 @@ class LXMessage:
else: else:
return None return None
def write_to_directory(self, directory_path): def packed_container(self):
file_name = RNS.hexrep(self.hash, delimit=False)
file_path = directory_path+"/"+file_name
try:
if not self.packed: if not self.packed:
self.pack() self.pack()
@ -421,10 +417,16 @@ class LXMessage:
"method": self.method "method": self.method
} }
packed_container = msgpack.packb(container) return msgpack.packb(container)
def write_to_directory(self, directory_path):
file_name = RNS.hexrep(self.hash, delimit=False)
file_path = directory_path+"/"+file_name
try:
file = open(file_path, "wb") file = open(file_path, "wb")
file.write(packed_container) file.write(self.packed_container())
file.close() file.close()
return file_path return file_path