From 1feceba8d752ee61523d48bbc5839d113cda4920 Mon Sep 17 00:00:00 2001 From: Rizwan Mohamed Ibrahim Date: Tue, 22 Sep 2020 16:17:15 +0530 Subject: [PATCH] Add UnicodeUrlConvertError as struct --- Sources/UnicodeURL/URL+Unicode.swift | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/UnicodeURL/URL+Unicode.swift b/Sources/UnicodeURL/URL+Unicode.swift index 768dfe4..5ef079e 100644 --- a/Sources/UnicodeURL/URL+Unicode.swift +++ b/Sources/UnicodeURL/URL+Unicode.swift @@ -6,13 +6,17 @@ import Foundation import IDNSDK -enum UnicodeURLConvertError: Int { - case none = 0 - case STD3NonLDH = 300 - case STD3Hyphen = 301 - case alreadyEncoded = 302 - case invalidDNSLength = 303 - case cicleCheck = 304 +public struct UnicodeURLConvertError: Error { + public enum ConvertError: Int { + case none = 0 + case STD3NonLDH = 300 + case STD3Hyphen = 301 + case alreadyEncoded = 302 + case invalidDNSLength = 303 + case cicleCheck = 304 + } + + public let error: ConvertError } public extension URL { @@ -114,8 +118,9 @@ public extension URL { } } - if ret != XCODE_SUCCESS { - throw NSError(domain:"kIFUnicodeURLErrorDomain", code:Int(ret), userInfo:nil) + if ret != XCODE_SUCCESS, + let error = UnicodeURLConvertError.ConvertError(rawValue: Int(ret)) { + throw UnicodeURLConvertError(error: error) } return hostname