Skip to content

Commit

Permalink
refactor(error): catch error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Hector Rondon authored and ajsb85 committed Oct 27, 2017
1 parent e0b668e commit 73d31ec
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Source/GlpiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class GlpiRequest {
}
case .failure(_ ):
SESSION_TOKEN = ""
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand Down Expand Up @@ -84,11 +84,11 @@ public class GlpiRequest {
}
}
} catch {
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
case .failure(_ ):
SESSION_TOKEN = ""
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -106,7 +106,7 @@ public class GlpiRequest {
SESSION_TOKEN = ""
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -123,7 +123,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -140,7 +140,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -160,7 +160,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(response.error)
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -177,7 +177,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -194,7 +194,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -211,7 +211,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -228,7 +228,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -245,7 +245,7 @@ public class GlpiRequest {
case .success(let result):
completion(result)
case .failure(_ ):
completion(GlpiRequest.handlerError(response))
completion(GlpiRequest.handlerError(response.data))
}
}
}
Expand All @@ -254,12 +254,12 @@ public class GlpiRequest {
handler Error
- return: error message
*/
class func handlerError(_ response: DataResponse<Any>) -> [String: String] {
class func handlerError(_ error: Data?) -> [String: String] {

var errorObj = [String]()
var errorDict = [String: String]()

if let data = response.data {
if let data = error {
errorObj = try! JSONSerialization.jsonObject(with: data) as? [String] ?? [String]()
}

Expand Down

0 comments on commit 73d31ec

Please sign in to comment.