From d42fecb0198a97c6f83de08f16c8d057e519d993 Mon Sep 17 00:00:00 2001 From: Shial Date: Thu, 24 May 2018 12:30:54 +1000 Subject: [PATCH] [0.1.6] Update URL create error message --- README.md | 2 +- SLazeKit.podspec | 4 ++-- Sources/SLazeKit/SLazeKit.swift | 24 ++++++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7db9c17..b7712d0 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Clone the repo and drag the folder `SLazeKit` into your Xcode project. **Swift Package Manager:** -Add the line `.package(url: "https://github.com/shial4/SLazeKit.git", from: "0.1.5"),` to your `Package.swift` +Add the line `.package(url: "https://github.com/shial4/SLazeKit.git", from: "0.1.6"),` to your `Package.swift` **Swift Package Manager in your iOS Project:** This project demonstrates a working method for using Swift Package Manager (SPM) to manage the dependencies of an iOS project. diff --git a/SLazeKit.podspec b/SLazeKit.podspec index 9c0d048..8e69a6c 100644 --- a/SLazeKit.podspec +++ b/SLazeKit.podspec @@ -1,9 +1,9 @@ Pod::Spec.new do |s| s.name = 'SLazeKit' - s.version = '0.1.5' + s.version = '0.1.6' s.summary = 'Swift restful manager.' s.description = <<-DESC - SLazeKit is an easy to use Swift restfull collection of extensions and classes. Don't spend hours writing your code to map your rest api request into models and serialization. stop wasting your time! + SLazeKit is an easy to use Swift restful collection of extensions and classes. Don't spend hours writing your code to map your rest api request into models and serialization. stop wasting your time! DESC s.homepage = 'https://github.com/shial4/SLazeKit.git' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Sources/SLazeKit/SLazeKit.swift b/Sources/SLazeKit/SLazeKit.swift index ec59004..6ae12d9 100644 --- a/Sources/SLazeKit/SLazeKit.swift +++ b/Sources/SLazeKit/SLazeKit.swift @@ -47,7 +47,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), urlConstructError(path, method, queryItems, body)) return nil } @@ -58,7 +58,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), urlConstructError(path, method, queryItems, body)) return nil } @@ -75,7 +75,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: String, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), nil, NSError(domain: "Unable to create url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), nil, urlConstructError(path, method, queryItems, body)) return nil } @@ -87,7 +87,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: B, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), nil, urlConstructError(path, method, queryItems, body)) return nil } @@ -104,7 +104,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), urlConstructError(path, method, queryItems, body)) return nil } @@ -121,7 +121,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, body: [B], handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), nil, urlConstructError(path, method, queryItems, body)) return nil } @@ -138,7 +138,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), urlConstructError(path, method, queryItems, nil)) return nil } return networkTask(request: urlRequest(url, method: method), handler: handler) @@ -146,7 +146,7 @@ public class SLazeKit { class func networkTask(path: String, method: HTTPMethod? = nil, queryItems: [URLQueryItem]? = nil, handler: @escaping (_ response: NetworkResponse, _ result: T?, _ error: Error?) -> Void) -> URLSessionDataTask? { guard let url = components(for: path, queryItems: queryItems)?.url else { - handler((nil,nil), nil, NSError(domain: "Unable to get url from components", code: NSURLErrorBadURL, userInfo: nil)) + handler((nil,nil), nil, urlConstructError(path, method, queryItems, nil)) return nil } return networkTask(request: urlRequest(url, method: method), handler: handler) @@ -167,6 +167,14 @@ public class SLazeKit { return urlComponents } + private class func urlConstructError(_ path: String, _ method: HTTPMethod? = nil, _ queryItems: [URLQueryItem]? = nil, _ body: Any?) -> NSError { + return NSError(domain: "", code: NSURLErrorBadURL, + userInfo: ["path":path, + "method":"\(method ?? .GET)", + "queryItems":"\(queryItems ?? [])", + "body":String(describing: body)]) + } + private class func synchronize(_ obj: Any) throws { guard let context = Config.newBackgroundContext() else { return } if let array = obj as? [EntityMapping] {