refactor: error messages in parsers
This commit is contained in:
parent
d97ca6e517
commit
a7f55fd648
11 changed files with 27 additions and 12 deletions
|
|
@ -77,8 +77,8 @@ class EpubCoverParser @Inject constructor() : CoverParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
coverImage
|
coverImage
|
||||||
} catch (_: Exception) {
|
} catch (e: Exception) {
|
||||||
logE(TAG, "Could not parse cover image.")
|
logE(TAG, "Could not parse cover image with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,15 @@ import kotlinx.coroutines.withContext
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.core.ui.UIText
|
import ua.acclorite.book_story.core.ui.UIText
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "EpubFileParser"
|
||||||
|
|
||||||
class EpubFileParser @Inject constructor() : FileParser {
|
class EpubFileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
|
|
@ -76,7 +79,7 @@ class EpubFileParser @Inject constructor() : FileParser {
|
||||||
}
|
}
|
||||||
book
|
book
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse file with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@ package ua.acclorite.book_story.data.parser.file
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.core.ui.UIText
|
import ua.acclorite.book_story.core.ui.UIText
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "Fb2FileParser"
|
||||||
|
|
||||||
class Fb2FileParser @Inject constructor() : FileParser {
|
class Fb2FileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
|
|
@ -56,7 +59,7 @@ class Fb2FileParser @Inject constructor() : FileParser {
|
||||||
coverImage = null
|
coverImage = null
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse file with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,14 @@ package ua.acclorite.book_story.data.parser.file
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.jsoup.parser.Parser
|
import org.jsoup.parser.Parser
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.core.ui.UIText
|
import ua.acclorite.book_story.core.ui.UIText
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "HtmlFileParser"
|
||||||
|
|
||||||
class HtmlFileParser @Inject constructor() : FileParser {
|
class HtmlFileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
|
|
@ -42,7 +45,7 @@ class HtmlFileParser @Inject constructor() : FileParser {
|
||||||
coverImage = null
|
coverImage = null
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse file with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,14 @@ import android.app.Application
|
||||||
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
|
import com.tom_roush.pdfbox.android.PDFBoxResourceLoader
|
||||||
import com.tom_roush.pdfbox.pdmodel.PDDocument
|
import com.tom_roush.pdfbox.pdmodel.PDDocument
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.core.ui.UIText
|
import ua.acclorite.book_story.core.ui.UIText
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "PdfFileParser"
|
||||||
|
|
||||||
class PdfFileParser @Inject constructor(
|
class PdfFileParser @Inject constructor(
|
||||||
private val application: Application
|
private val application: Application
|
||||||
) : FileParser {
|
) : FileParser {
|
||||||
|
|
@ -47,7 +50,7 @@ class PdfFileParser @Inject constructor(
|
||||||
coverImage = null
|
coverImage = null
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse file with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,14 @@
|
||||||
package ua.acclorite.book_story.data.parser.file
|
package ua.acclorite.book_story.data.parser.file
|
||||||
|
|
||||||
import ua.acclorite.book_story.R
|
import ua.acclorite.book_story.R
|
||||||
|
import ua.acclorite.book_story.core.log.logE
|
||||||
import ua.acclorite.book_story.core.ui.UIText
|
import ua.acclorite.book_story.core.ui.UIText
|
||||||
import ua.acclorite.book_story.data.model.file.CachedFile
|
import ua.acclorite.book_story.data.model.file.CachedFile
|
||||||
import ua.acclorite.book_story.domain.model.library.Book
|
import ua.acclorite.book_story.domain.model.library.Book
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val TAG = "TxtFileParser"
|
||||||
|
|
||||||
class TxtFileParser @Inject constructor() : FileParser {
|
class TxtFileParser @Inject constructor() : FileParser {
|
||||||
|
|
||||||
override suspend fun parse(cachedFile: CachedFile): Book? {
|
override suspend fun parse(cachedFile: CachedFile): Book? {
|
||||||
|
|
@ -31,7 +34,7 @@ class TxtFileParser @Inject constructor() : FileParser {
|
||||||
coverImage = null
|
coverImage = null
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse file with message: ${e.message}.")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ class EpubTextParser @Inject constructor(
|
||||||
logI(TAG, "Successfully finished EPUB parsing.")
|
logI(TAG, "Successfully finished EPUB parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
logE(TAG, "Could not parse text with message: ${e.message}.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class HtmlTextParser @Inject constructor(
|
||||||
logI(TAG, "Successfully finished HTML parsing.")
|
logI(TAG, "Successfully finished HTML parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logE(TAG, e.message ?: "")
|
logE(TAG, "Could not parse text with message: ${e.message}.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ class PdfTextParser @Inject constructor(
|
||||||
logI(TAG, "Successfully finished PDF parsing.")
|
logI(TAG, "Successfully finished PDF parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logE(TAG, e.message ?: "")
|
logE(TAG, "Could not parse text with message: ${e.message}.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ class TxtTextParser @Inject constructor(
|
||||||
logI(TAG, "Successfully finished TXT parsing.")
|
logI(TAG, "Successfully finished TXT parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logE(TAG, e.message ?: "")
|
logE(TAG, "Could not parse text with message: ${e.message}.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class XmlTextParser @Inject constructor(
|
||||||
logI(TAG, "Successfully finished XML parsing.")
|
logI(TAG, "Successfully finished XML parsing.")
|
||||||
readerText
|
readerText
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logE(TAG, e.message ?: "")
|
logE(TAG, "Could not parse text with message: ${e.message}.")
|
||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue