Skip to content

Commit

Permalink
[Feat] TeamSparker#603 - 이미 인증한 사용자에게 스파크보내기를 할 경우 440 에러코드를 넘겨줌
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun99999 committed May 9, 2022
1 parent 52defbe commit 637353b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Spark-iOS/Spark-iOS/Source/NetworkServices/Room/RoomAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public class RoomAPI {
case .success(let response):
let statusCode = response.statusCode
let data = response.data
let networkResult = self.judgeStatus(by: statusCode, data)
let networkResult = self.judgeSendSparkStatus(by: statusCode, data)
completion(networkResult)

case .failure(let err):
Expand All @@ -225,6 +225,22 @@ public class RoomAPI {
}
}

private func judgeSendSparkStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {
let decoder = JSONDecoder()
guard let decodedData = try? decoder.decode(GenericResponse<String>.self, from: data)
else { return .pathErr }
switch statusCode {
case 200:
return .success(decodedData.message)
case 400..<500:
return .requestErr(decodedData.status)
case 500:
return .serverErr
default:
return .networkFail
}
}

func setConsiderRest(roomID: Int, statusType: String, completion: @escaping(NetworkResult<Any>) -> Void) {
roomProvider.request(.setConsiderRest(roomID: roomID, statusType: statusType)) { result in
switch result {
Expand Down

0 comments on commit 637353b

Please sign in to comment.