-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6908255
commit 4005402
Showing
18 changed files
with
231 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...PNCommunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Extensions/Foundation/Error+Ext.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Error+Ext.swift | ||
// SOLARdVPNCommunityCoreiOS | ||
// | ||
// Created by Lika Vorobeva on 10.10.2022. | ||
// | ||
|
||
import Foundation | ||
import Vapor | ||
import GRPC | ||
import SOLARAPI | ||
|
||
extension Error { | ||
var innerError: InnerError? { | ||
if let grpc = self as? (any GRPCErrorProtocol) { | ||
let status = grpc.makeGRPCStatus() | ||
|
||
return .init(code: status.code.rawValue, message: status.message ?? "unknown_error") | ||
} | ||
|
||
if let networkError = self as? NetworkError { | ||
return .init(code: networkError.code, message: networkError.message ?? "unknown_error") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func encodedError(status: UInt = 500) -> Abort { | ||
guard let innerError = self.innerError else { | ||
return .init(.internalServerError, reason: self.localizedDescription) | ||
} | ||
guard let reason = innerError.toData()?.string else { | ||
return .init(.internalServerError) | ||
} | ||
return .init(.custom(code: status, reasonPhrase: reason)) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...mmunityCoreiOS/SOLARdVPNCommunityCoreiOS/Common/Extensions/Wallet/WalletService+Ext.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// | ||
// WalletService+Ext.swift | ||
// SOLARdVPNCommunityCoreiOS | ||
// | ||
// Created by Lika Vorobeva on 10.10.2022. | ||
// | ||
|
||
import Foundation | ||
import SentinelWallet | ||
|
||
|
||
extension WalletServiceError: LocalizedError { | ||
public var errorDescription: String? { | ||
switch self { | ||
case .accountMatchesDestination: | ||
return "account_matches_destination" | ||
case .missingMnemonics: | ||
return "missing_mnemonics" | ||
case .missingAuthorization: | ||
return "missing_authorization" | ||
case .notEnoughTokens: | ||
return "not_enough_tokens" | ||
case .mnemonicsDoNotMatch: | ||
return "mnemonic_do_not_match" | ||
case .savingError: | ||
return "saving_error" | ||
} | ||
} | ||
} | ||
|
||
extension WalletServiceError { | ||
var body: SingleInnerError { | ||
switch self { | ||
case .accountMatchesDestination: | ||
return .init(code: 403, message: localizedDescription) | ||
case .missingMnemonics: | ||
return .init(code: 401, message: localizedDescription) | ||
case .missingAuthorization: | ||
return .init(code: 401, message: localizedDescription) | ||
case .notEnoughTokens: | ||
return .init(code: 402, message: localizedDescription) | ||
case .mnemonicsDoNotMatch: | ||
return .init(code: 401, message: localizedDescription) | ||
case .savingError: | ||
return .init(code: 500, message: localizedDescription) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.