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] #193 - 액세스 토큰 만료 로직 구현 #207

Merged
merged 7 commits into from
Jan 7, 2024
Merged
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion iOS-NOTTODO/iOS-NOTTODO/Network/Base/NetworkLoggerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by 김민서 on 2023/02/23.
//

import Foundation
import UIKit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIKit도 이제 없어두 될거 같아여!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹!
db4086c


import Moya

Expand Down Expand Up @@ -56,6 +56,15 @@ final class MoyaLoggingPlugin: PluginType {
}
log.append("------------------- END HTTP (\(response.data.count)-byte body) -------------------")
print(log)

switch statusCode {
case 200..<300:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 글구 케이스를 이렇게 나누면 400에러나 500에러가 뜰때도 보내버려서 분기처리 조건을 수정해야 할듯 합니다~!
아마 서버에서 401을 줄텐데 401인 경우만 이렇게 해야할 것 같아요~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아!! 401만 분기처리해서 올릴게요:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return
default:

let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as! SceneDelegate
sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: AuthViewController())
}
Copy link
Member

@hyesuuou hyesuuou Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요렇게 해줘도 동작은 하지만 사실 요 플러그인의 기능은 로깅이니까
로깅하는 역할에서 화면 전환을 알 필요가 있나? 에 대해서는 한번 더 생각해보면 좋을 것 같습니다~
클래스의 역할만 보면 UIKit이 필요하지 않을 것 같은데 이 화면전환으로 인해서 import 해야하니까 요런 부분도 역할 분리가 잘 된게 맞는지 의심해볼 포인트 같아요!

저희 플젝에서는 Moya를 쓰니까 Moya를 기준으로 알아보면 좋을거를 좀 소개를 해보자면
Moya가 Alamofire를 감싼 형태인데, Alamofire에서 Intercepter라고 해서
요청을 보내기 전이나 후에 필요한 처리를 할 수 있는 API를 제공하고 있어요!

요걸쓰면 응답이 내려온 시점에 특정 작업을 수행하기 위해서 이 부분도 해결되지 않을까 싶네여!

이거를 Moya에서도 provider를 생성할때 LogginPlugin을 넣어준것 처럼

provider = MoyaProvider<~~Router>(
        session: Session(interceptor: 만들어준인터셉터()),
        plugins: [MoyaLoggingPlugin()]
    )

이렇게 만들어주면 해당 provider를 사용하는 곳에선 모두 저 인터셉트를 거치게 됩미다~

https://ios-development.tistory.com/730

요 블로그 보면 좋을 것같아요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 ! interceptor 활용해서 수정할게요 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

func onFail(_ error: MoyaError, target: TargetType) {
Expand Down