-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactoring] Starlink -> Moya 교체 작업 #185
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
base: develop
Are you sure you want to change the base?
Conversation
let networkEventMonitor = NetworkEventMonitor() | ||
let tokenCredential = TokenAuthenticationCredential() | ||
let authenticatorInterceptor = AuthenticationInterceptor( | ||
authenticator: TokenAuthenticator(), | ||
credential: tokenCredential | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenInterceptor 작업
AccessToken이 만료되면 자동으로 갱신 받아서 Token 교체
static func plain<T: TargetType>() -> MoyaProvider<T> { | ||
let configuration = URLSessionConfiguration.default | ||
configuration.timeoutIntervalForRequest = 10 // 요청에 대한 타임아웃 10초 | ||
configuration.timeoutIntervalForResource = 10 // 리소스에 대한 타임아웃 10초 | ||
|
||
let networkEventMonitor = NetworkEventMonitor() | ||
let session = Session( | ||
configuration: configuration, | ||
eventMonitors: [networkEventMonitor] | ||
) | ||
|
||
return MoyaProvider<T>(session: session) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로그인 전 인증이 필요없는 요청의 provider
|
||
import Alamofire | ||
|
||
final class NetworkEventMonitor: EventMonitor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Network 통신 Logger
이 로그 때문에 다른 로그가 잘 안보인다면 나중에 삭제해도 괜춘
public enum NetworkError: Error { | ||
case underlying(Response) | ||
case failure(Error) | ||
case decoding | ||
case unknown | ||
case tokenEmpty | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네트워크 레이어 에러 정의 (추후 고도화 필요해유)
public extension TargetType { | ||
// Header 기본 구현 | ||
var headers: [String: String]? { | ||
Headers.common |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
매번 헤더 넣기 귀찮아서 TargetType 기본 구현으로 빼놨어요
private var tokenRepository: TokenRepository { | ||
ClogDI.container.resolve(TokenRepository.self)! | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NetworkLayer에서 DataLayer를 몰라요
그래서 Domain에 TokenRepository 인터페이스 만들어서 의존성 역전 시켰어요
with response: HTTPURLResponse, | ||
failDueToAuthenticationError error: any Error | ||
) -> Bool { | ||
return response.statusCode == 401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
401일 때 인터셉터 발동
NotificationCenter.default.post(name: .didKickOut, object: nil) | ||
completion(.failure(failure)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리프레시 실패시 kickout
let token = try await tokenRepository.refresh(refreshToken) | ||
tokenRepository.saveToken(token) | ||
completion(.success(Credential())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refresh 토큰 재발급 및 저장
import Foundation | ||
import Moya | ||
|
||
public extension Encodable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryParameter 넣을 때 항상 [String: Any] 형태로 변환해서 넣는 부분이 코드가 길어져서
queryParameter를 Encodable 객체로 받아서 사용해서
request.toSafeRequestParameter()
이 한줄로 끝낼 수 있도록 작업해놨어요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파싱에 실패한다면 .requestPlain
으로 리턴해요
변경 유형
변경 사항
관련링크 (JIRA)
관련 로그, 스크린샷