-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat #144: getServerURL RxMoya 방식 구현
- Loading branch information
1 parent
f554462
commit 8c90a07
Showing
5 changed files
with
60 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
Project_Timer/Data/DTO/ServerURLDTO.swift → ...mer/Data/Response/ServerURLResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// TTProvider.swift | ||
// Project_Timer | ||
// | ||
// Created by Kang Minsang on 2024/05/15. | ||
// Copyright © 2024 FDEE. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
import Moya | ||
import RxMoya | ||
|
||
/// 공통적인 에러를 반환하는 Provider | ||
final class TTProvider<T: TargetType>: MoyaProvider<T> { | ||
func request(_ token: T) -> Single<Response> { | ||
return super.rx.request(token) | ||
.catch { error in | ||
self.handleError(error) | ||
} | ||
} | ||
|
||
private func handleError(_ error: Error) -> Single<Response> { | ||
if let moyaError = error as? MoyaError { | ||
switch moyaError { | ||
case .statusCode(let response): | ||
return Single.error(NetworkError.serverError(statusCode: response.statusCode)) | ||
default: | ||
return Single.error(NetworkError.FAIL) | ||
} | ||
} | ||
return Single.error(NetworkError.FAIL) | ||
} | ||
} |