[0.1.6] Update URL create error message

This commit is contained in:
Shial 2018-05-24 12:30:54 +10:00
parent 8acb20a4a3
commit d42fecb019
3 changed files with 19 additions and 11 deletions

View File

@ -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.

View File

@ -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' }

View File

@ -47,7 +47,7 @@ public class SLazeKit<Config: LazeConfiguration> {
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<Config: LazeConfiguration> {
class func networkTask<B: Encodable>(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<Config: LazeConfiguration> {
class func networkTask<T: Decodable>(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<Config: LazeConfiguration> {
class func networkTask<T: Decodable, B: Encodable>(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<Config: LazeConfiguration> {
class func networkTask<B: Encodable>(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<Config: LazeConfiguration> {
class func networkTask<T: Decodable, B: Encodable>(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<Config: LazeConfiguration> {
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<Config: LazeConfiguration> {
class func networkTask<T: Decodable>(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<Config: LazeConfiguration> {
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] {