Skip to content

Commit 9fe5b12

Browse files
committed
unnecessary failable Initializer
1 parent 7f0ce4e commit 9fe5b12

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

StudyplusSDK/StudyplusAPIRequest.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ internal struct StudyplusAPIRequest {
4646
}, failure: { statusCode, response in
4747

4848
DispatchQueue.main.async {
49-
if let message: String = response?["message"] as? String, let error = StudyplusError(statusCode, message) {
50-
failure(error)
49+
if let message: String = response?["message"] as? String {
50+
failure(StudyplusError(statusCode, message))
5151
} else {
5252
failure(.unknownReason("Not connected to the network or StudyplusAPIRequest Error"))
5353
}
@@ -88,37 +88,37 @@ internal struct StudyplusAPIRequest {
8888
if httpResponse.statusCode == 200 || httpResponse.statusCode == 201 || httpResponse.statusCode == 202 {
8989

9090
if let data = data {
91-
do {
92-
let jsonObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
93-
success(jsonObject as? [String : Any])
94-
return
95-
} catch {
96-
#if DEBUG
97-
print("-- StudyplusAPIRequest Json Error Path: \(url.absoluteString), Method: \(method), Description: \(error.localizedDescription) --")
98-
#endif
99-
failure(httpResponse.statusCode, ["message": error.localizedDescription])
100-
}
91+
do {
92+
let jsonObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
93+
success(jsonObject as? [String : Any])
94+
return
95+
} catch {
96+
#if DEBUG
97+
print("-- StudyplusAPIRequest Json Error Path: \(url.absoluteString), Method: \(method), Description: \(error.localizedDescription) --")
98+
#endif
99+
failure(httpResponse.statusCode, ["message": error.localizedDescription])
100+
}
101101
}
102102

103103
} else if httpResponse.statusCode == 204 {
104-
success(nil)
105-
return
104+
success(nil)
105+
return
106106

107107
} else {
108-
#if DEBUG
109-
print("-- StudyplusAPIRequest Path: \(url.absoluteString), Method: \(method), StatusCode: \(httpResponse.statusCode) --")
110-
#endif
108+
#if DEBUG
109+
print("-- StudyplusAPIRequest Path: \(url.absoluteString), Method: \(method), StatusCode: \(httpResponse.statusCode) --")
110+
#endif
111111
if let data = data {
112-
do {
113-
let jsonObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
114-
failure(httpResponse.statusCode, jsonObject as? [String: Any])
115-
return
116-
117-
} catch let jsonError {
118-
failure(httpResponse.statusCode, ["message": jsonError.localizedDescription])
119-
}
120-
}
121-
}
112+
do {
113+
let jsonObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
114+
failure(httpResponse.statusCode, jsonObject as? [String: Any])
115+
return
116+
117+
} catch let jsonError {
118+
failure(httpResponse.statusCode, ["message": jsonError.localizedDescription])
119+
}
120+
}
121+
}
122122
}
123123
}
124124

StudyplusSDK/StudyplusError.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ public enum StudyplusError {
6666
}
6767
}
6868

69-
internal init?(_ httpStatusCode: Int, _ message: String) {
70-
71-
if httpStatusCode < 400 || 599 < httpStatusCode {
72-
return nil
73-
}
69+
internal init(_ httpStatusCode: Int, _ message: String) {
7470

7571
switch (httpStatusCode) {
7672
case 400:

0 commit comments

Comments
 (0)