Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #603 - 인증한 유저에게 스파크 보내기했을 때 예외처리 #606

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ extension SendSparkVC {
// MARK: - @objc Function
@objc
private func sendSparkWithMessage() {
setFeedbackGenerator()
sendSparkWithAPI(content: textField.text ?? "")
Analytics.logEvent(Tracking.Select.clickSparkInputText, parameters: nil)
}
Expand Down Expand Up @@ -475,13 +476,7 @@ extension SendSparkVC: UICollectionViewDataSource {

// MARK: - UICollectionViewDelegate

extension SendSparkVC: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
impactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
impactFeedbackGenerator?.impactOccurred()
impactFeedbackGenerator = nil
}
}
extension SendSparkVC: UICollectionViewDelegate { }

// MARK: Network

Expand All @@ -494,8 +489,18 @@ extension SendSparkVC {
self.dismiss(animated: true) {
presentVC?.showSparkToast(x: 20, y: 44, message: "\(self.userName ?? "")에게 스파크를 보냈어요!")
}
case .requestErr(let message):
print("sendSparkWithAPI - requestErr: \(message)")
case .requestErr(let status):
if status as? Int == 440 {
let presentVC = self.presentingViewController
self.dismiss(animated: true) {
NotificationCenter.default.post(name: .updateHabitRoom, object: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
presentVC?.showSparkToast(x: 20, y: 44, message: "\(self.userName ?? "")에게 스파크를 보냈어요!")
}
}
}

print("sendSparkWithAPI - requestErr: \(status)")
case .pathErr:
print("sendSparkWithAPI - pathErr")
case .serverErr:
Expand Down