Skip to content

Commit

Permalink
[0.1.6] Update URL create error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Shial committed May 24, 2018
1 parent 8acb20a commit d42fecb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions SLazeKit.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
24 changes: 16 additions & 8 deletions Sources/SLazeKit/SLazeKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -138,15 +138,15 @@ 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)
}

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)
Expand All @@ -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] {
Expand Down

0 comments on commit d42fecb

Please sign in to comment.