From 1d5d2d00660eef4dda2be290f6461ca089c8df25 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 5 Oct 2021 22:52:39 +0300 Subject: [PATCH 1/2] Surface ComposeMessageError details to user --- FlowCrypt/Core/Core.swift | 28 +++++++++++++------ .../ComposeMessageService.swift | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/FlowCrypt/Core/Core.swift b/FlowCrypt/Core/Core.swift index 044d958a5..08425136d 100644 --- a/FlowCrypt/Core/Core.swift +++ b/FlowCrypt/Core/Core.swift @@ -6,7 +6,7 @@ import FlowCryptCommon import JavaScriptCore import Combine -enum CoreError: Error, Equatable { +enum CoreError: LocalizedError, Equatable { case exception(String) case notReady(String) case format(String) @@ -18,18 +18,30 @@ enum CoreError: Error, Equatable { // wrong value passed into a function case value(String) - init?(coreError: CoreRes.Error) { - guard let errorType = coreError.error.type else { - return nil - } - switch errorType { + init(coreError: CoreRes.Error) { + switch coreError.error.type { case "format": self = .format(coreError.error.message) case "key_mismatch": self = .keyMismatch(coreError.error.message) case "no_mdc": self = .noMDC(coreError.error.message) case "bad_mdc": self = .badMDC(coreError.error.message) case "need_passphrase": self = .needPassphrase(coreError.error.message) case "wrong_passphrase": self = .wrongPassphrase(coreError.error.message) - default: return nil + default: self = .exception(coreError.error.message + "\n" + (coreError.error.stack ?? "no stack")) + } + } + + var errorDescription: String? { + switch self { + case .exception(let message), + .notReady(let message), + .format(let message), + .keyMismatch(let message), + .noMDC(let message), + .badMDC(let message), + .needPassphrase(let message), + .wrongPassphrase(let message), + .value(let message): + return message } } } @@ -233,7 +245,7 @@ final class Core: KeyDecrypter, CoreComposeMessageType { let errMsg = "------ js err -------\nCore \(endpoint):\n\(error.error.message)\n\(error.error.stack ?? "no stack")\n------- end js err -----" logger.logError(errMsg) - throw CoreError.init(coreError: error) ?? CoreError.exception(errMsg) + throw CoreError(coreError: error) } return RawRes(json: resJsonData, data: Data(rawResponse)) diff --git a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift index e0bc56092..0231eb7ff 100644 --- a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift +++ b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift @@ -137,7 +137,7 @@ final class ComposeMessageService { return core.composeEmail( msg: msg, fmt: MsgFmt.encryptInline, - pubKeys: msg.pubKeys + pubKeys: ["Test"] ) .map(\.mimeEncoded) .eraseToAnyPublisher() From cba65dac9f5013bb084c98b5eed60c40cce7c24e Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 5 Oct 2021 22:54:12 +0300 Subject: [PATCH 2/2] Surface ComposeMessageError details to user --- .../Compose Message Service/ComposeMessageService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift index 0231eb7ff..e0bc56092 100644 --- a/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift +++ b/FlowCrypt/Functionality/Services/Compose Message Service/ComposeMessageService.swift @@ -137,7 +137,7 @@ final class ComposeMessageService { return core.composeEmail( msg: msg, fmt: MsgFmt.encryptInline, - pubKeys: ["Test"] + pubKeys: msg.pubKeys ) .map(\.mimeEncoded) .eraseToAnyPublisher()