Skip to content

Commit

Permalink
Merge pull request #96 from niscy-eudiw/feature/credential-issuer-id-…
Browse files Browse the repository at this point in the history
…construct

Credential issuer id update
  • Loading branch information
dtsiflit authored Nov 4, 2024
2 parents 1a1a876 + 585203d commit 56eca59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/Entities/CredentialIssuer/CredentialIssuerId.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ 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
let validURL = URL(string: string),
validURL.scheme == "https",
validURL.fragment == nil
else {
throw CredentialError.genericError
throw CredentialError.invalidScheme
}

self.url = validURL
Expand All @@ -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)
}
}
17 changes: 16 additions & 1 deletion Sources/Entities/Errors/CredentialError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 56eca59

Please sign in to comment.