forked from LiveCarta/BookConverter
Add try except blocks where is needed
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import codecs
|
||||
import logging
|
||||
|
||||
from src.book_solver import BookSolver
|
||||
from src.util.helpers import BookLogger
|
||||
@@ -30,11 +31,19 @@ class EpubBook(BookSolver):
|
||||
json for LiveCarta platform
|
||||
|
||||
"""
|
||||
style_preprocessor = StyleReader()
|
||||
# Parses and cleans html, gets list of tags, gets footnotes
|
||||
try:
|
||||
html_preprocessor = HtmlPresetsProcessor(
|
||||
logger=self.logger_object, preset_path="presets/epub_presets.json")
|
||||
style_preprocessor = StyleReader()
|
||||
html_processor = HtmlEpubProcessor(logger=self.logger_object,
|
||||
html_preprocessor=html_preprocessor)
|
||||
except Exception as exc:
|
||||
self.logger_object.log(
|
||||
"Error has occurred while processing .html", logging.ERROR)
|
||||
self.logger_object.log_error_to_main_log()
|
||||
self.status_wrapper.set_error()
|
||||
raise exc
|
||||
json_converter = EpubConverter(
|
||||
self.book_path, access=self.access, logger=self.logger_object,
|
||||
style_processor=style_preprocessor, html_processor=html_processor)
|
||||
|
||||
@@ -109,6 +109,7 @@ class StyleReader:
|
||||
return constraints_on_value, value_not_in_possible_values_list
|
||||
|
||||
def update_inline_styles_to_livecarta_convention(self, split_style: list) -> list:
|
||||
try:
|
||||
for i, style in reversed(list(enumerate(split_style))):
|
||||
style_name, style_value = style.split(":")
|
||||
if style_name not in LiveCartaConfig.LIVECARTA_STYLE_ATTRS:
|
||||
@@ -127,6 +128,8 @@ class StyleReader:
|
||||
func = self.LIVECARTA_STYLE_ATTRS_MAPPING[style_name]
|
||||
style_value = func(cleaned_value)
|
||||
split_style[i] = style_name + ":" + style_value
|
||||
except ValueError as ve:
|
||||
print(f"Style value isn't correct.")
|
||||
return split_style
|
||||
|
||||
def build_inline_style_content(self, style: str) -> str:
|
||||
|
||||
Reference in New Issue
Block a user