diff --git a/Sources/Entities/CredentialIssuer/CredentialIssuerId.swift b/Sources/Entities/CredentialIssuer/CredentialIssuerId.swift index b48f263..c38ed14 100644 --- a/Sources/Entities/CredentialIssuer/CredentialIssuerId.swift +++ b/Sources/Entities/CredentialIssuer/CredentialIssuerId.swift @@ -21,7 +21,7 @@ public struct CredentialIssuerId: Codable, Equatable { public init(_ string: String) throws { if let queryItems = URLComponents(string: string)?.queryItems, queryItems.count > 0 { - throw CredentialError.genericError + throw CredentialError.extraneousQueryComponents } guard @@ -29,7 +29,7 @@ public struct CredentialIssuerId: Codable, Equatable { validURL.scheme == "https", validURL.fragment == nil else { - throw CredentialError.genericError + throw CredentialError.invalidScheme } self.url = validURL @@ -43,6 +43,6 @@ public struct CredentialIssuerId: Codable, Equatable { public init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() let urlString = try container.decode(String.self) - url = try URL(string: urlString) ?? { throw ValidationError.error(reason: "Invalid credential_issuer URL")}() + try self.init(urlString) } } diff --git a/Sources/Entities/Errors/CredentialError.swift b/Sources/Entities/Errors/CredentialError.swift index 2be6d0e..ec4a86c 100644 --- a/Sources/Entities/Errors/CredentialError.swift +++ b/Sources/Entities/Errors/CredentialError.swift @@ -15,7 +15,22 @@ */ import Foundation -public enum CredentialError: Error { +public enum CredentialError: LocalizedError { case genericError case issuerDoesNotSupportDeferredIssuance + case extraneousQueryComponents + case invalidScheme + + public var errorDescription: String? { + switch self { + case .genericError: + return "Something went wrong" + case .issuerDoesNotSupportDeferredIssuance: + return "Issuer does not support deferred issuance" + case .extraneousQueryComponents: + return "Extraneous query components" + case .invalidScheme: + return "Invalid scheme" + } + } }