I am not able to find out the what is the issue , just to filter out response based on status code as follow:
The code should be filter out the response based on the status code and return response and data
as observable.
There are few issues with your approach:
Observable.create
when you have URLSession.shared.rx.response
that is already returning Observable
?flatMap
should return an Observable
but you are not returning anything from thereURLSession.shared.rx.data
that does the statusCode
check for you.decode
operator for decodingT
but is named getUsers
?Observable
inside Observable.create
so your reactive chain will never runGiven these issue you can adapt your code to:
func getUsers<T: Codable>(urlStr: String) -> Observable<T> {
guard let url = URL(string: urlStr) else { return .empty() }
return URLSession.shared.rx.data(request: .init(url: url))
.decode(type: T.self, decoder: JSONDecoder())
}