Renamed FetchEmailsError to FetchEmailError

This commit is contained in:
dankito 2024-11-28 03:41:14 +01:00
parent 9480bc0282
commit 54a5227fb7
7 changed files with 17 additions and 17 deletions

View File

@ -62,7 +62,7 @@ open class EmailsFetcher(
}
} catch (e: Throwable) {
log.error(e) { "Listening to new emails of '${account.username}' failed" }
options.onError?.invoke(FetchEmailsError(FetchEmailsErrorType.ListenForNewEmails, null, e))
options.onError?.invoke(FetchEmailError(FetchEmailErrorType.ListenForNewEmails, null, e))
}
}
@ -206,7 +206,7 @@ open class EmailsFetcher(
}
} catch (e: Throwable) {
log.error(e) { "Could not check attachment '${messagePart.part.fileName}' (${messagePart.mediaType}) for eInvoice" }
status.addError(FetchEmailsErrorType.GetAttachment, messagePart.part, e)
status.addError(FetchEmailErrorType.GetAttachment, messagePart.part, e)
}
return null
@ -307,7 +307,7 @@ open class EmailsFetcher(
}
} catch (e: Throwable) {
log.error(e) { "Could not get message body for media type '$mediaType'" }
status.addError(FetchEmailsErrorType.GetMesssageBody, parts.map { it.part }, e)
status.addError(FetchEmailErrorType.GetMesssageBody, parts.map { it.part }, e)
null
}

View File

@ -1,7 +1,7 @@
package net.codinux.invoicing.email
data class FetchEmailsError(
val type: FetchEmailsErrorType,
data class FetchEmailError(
val type: FetchEmailErrorType,
val messageNumber: Int?,
val error: Throwable
)

View File

@ -1,6 +1,6 @@
package net.codinux.invoicing.email
enum class FetchEmailsErrorType {
enum class FetchEmailErrorType {
GetEmail,
GetMesssageBody,

View File

@ -25,7 +25,7 @@ open class FetchEmailsOptions(
val emailFolderName: String = "INBOX",
val connectTimeoutSeconds: Int = 5,
val onError: ((FetchEmailsError) -> Unit)? = null,
val onError: ((FetchEmailError) -> Unit)? = null,
val onEmailReceived: ((Email) -> Unit)? = null
) {
companion object {

View File

@ -5,5 +5,5 @@ import net.codinux.invoicing.email.model.Email
data class FetchEmailsResult(
val emails: List<Email>,
val overallError: Throwable?,
val messageSpecificErrors: List<FetchEmailsError> = emptyList()
val messageSpecificErrors: List<FetchEmailError> = emptyList()
)

View File

@ -12,7 +12,7 @@ data class FetchEmailsStatus(
val account: EmailAccount,
val folder: IMAPFolder,
val options: FetchEmailsOptions,
val messageSpecificErrors: MutableList<FetchEmailsError> = mutableListOf()
val messageSpecificErrors: MutableList<FetchEmailError> = mutableListOf()
) {
val userAttachmentsDownloadDirectory: File by lazy {
@ -22,16 +22,16 @@ data class FetchEmailsStatus(
}
fun addError(type: FetchEmailsErrorType, parts: Collection<Part>, error: Throwable) =
addError(FetchEmailsError(type, parts.firstNotNullOfOrNull { getMessage(it) }?.messageNumber, error))
fun addError(type: FetchEmailErrorType, parts: Collection<Part>, error: Throwable) =
addError(FetchEmailError(type, parts.firstNotNullOfOrNull { getMessage(it) }?.messageNumber, error))
fun addError(type: FetchEmailsErrorType, part: Part, error: Throwable) =
addError(FetchEmailsError(type, getMessage(part)?.messageNumber, error))
fun addError(type: FetchEmailErrorType, part: Part, error: Throwable) =
addError(FetchEmailError(type, getMessage(part)?.messageNumber, error))
fun addError(type: FetchEmailsErrorType, messageNumber: Int?, error: Throwable) =
addError(FetchEmailsError(type, messageNumber, error))
fun addError(type: FetchEmailErrorType, messageNumber: Int?, error: Throwable) =
addError(FetchEmailError(type, messageNumber, error))
fun addError(error: FetchEmailsError) {
fun addError(error: FetchEmailError) {
messageSpecificErrors.add(error)
options.onError?.invoke(error)

View File

@ -16,7 +16,7 @@ open class ListenForNewMailsOptions(
emailFolderName: String = "INBOX",
connectTimeoutSeconds: Int = 5,
onError: ((FetchEmailsError) -> Unit)? = null,
onError: ((FetchEmailError) -> Unit)? = null,
onEmailReceived: (Email) -> Unit
) : FetchEmailsOptions(
null,