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

[Refactor] JudgeStatus 메서드 개선 #620

Open
L-j-h-c opened this issue May 13, 2022 · 2 comments
Open

[Refactor] JudgeStatus 메서드 개선 #620

L-j-h-c opened this issue May 13, 2022 · 2 comments
Assignees

Comments

@L-j-h-c
Copy link
Member

L-j-h-c commented May 13, 2022

🛠 Issue

이번에 4차과제를 하면서 반복되는 judgeStatus 메서드를 하나로 통일할 수 있도록 아래와 같이 만들어봤는데 어떻게 생각하시나용?
@hyun99999 @yangsubinn

    func myRoomCertiChangeFetch(roomID: Int, lastID: Int, size: Int, completion: @escaping (NetworkResult<Any>) -> Void) {
        userProvider.request(.myRoomCertiChangeFetch(roomID: roomID, lastID: lastID, size: size)) { (result) in
            switch result {
            case .success(let response):
                let statusCode = response.statusCode
                let data = response.data

                let networkResult = self.judeStatus(by: statusCode, data, type:  MyRoomCertification.self)
                completion(networkResult)

            case .failure(let err):
                print(err)
            }
        }
    }
    
    private func judgeStatus<T: Codable>(by statusCode: Int, _ data: Data, type: T.Type) -> NetworkResult<Any> {
        let decoder = JSONDecoder()
        guard let decodedData = try? decoder.decode(GenericResponse<T>.self, from: data)
        else { return .pathErr }
        switch statusCode {
        case 200:
            return .success(decodedData.data ?? "None-Data")
        case 400..<500:
            return .requestErr(decodedData.message)
        case 500:
            return .serverErr
        default:
            return .networkFail
        }
    }

📝 To-do

  • [ ]
@L-j-h-c L-j-h-c self-assigned this May 13, 2022
@hyun99999
Copy link
Member

너무 좋네요! 확실한 리펙입니당
지금 200 혹은 201 일때 성공하는 경우가 있을 수도 있고 400 이랑 500 사이에 분기처리가 있는 경우도 있어요!
유의해서 진행하면 좋을거 같네용 준호 멋집니당🙈

@yangsubinn
Copy link
Member

좋슴니다 ! 훨씬 더 효율적일 것 같아요 🤓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants