From 83fa4fbc814617df08c847a930aeb1aa7e4a569d Mon Sep 17 00:00:00 2001 From: dtsiflit Date: Thu, 31 Oct 2024 15:09:11 +0200 Subject: [PATCH 1/2] [fix] credential issuer id fix --- Sources/Entities/CredentialIssuer/CredentialIssuerId.swift | 6 +++--- Sources/Entities/Errors/CredentialError.swift | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) 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..468d822 100644 --- a/Sources/Entities/Errors/CredentialError.swift +++ b/Sources/Entities/Errors/CredentialError.swift @@ -18,4 +18,6 @@ import Foundation public enum CredentialError: Error { case genericError case issuerDoesNotSupportDeferredIssuance + case extraneousQueryComponents + case invalidScheme } From 96194dcce7d3ee992ca5c3887bc798f783608ffd Mon Sep 17 00:00:00 2001 From: dtsiflit Date: Fri, 1 Nov 2024 10:51:35 +0200 Subject: [PATCH 2/2] [fix] updated credential error --- Sources/Entities/Errors/CredentialError.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/Entities/Errors/CredentialError.swift b/Sources/Entities/Errors/CredentialError.swift index 468d822..ec4a86c 100644 --- a/Sources/Entities/Errors/CredentialError.swift +++ b/Sources/Entities/Errors/CredentialError.swift @@ -15,9 +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" + } + } }