0

How can I determine if the error in RxSwift is a 401.

I use this func

extension LoginInteractorApi {
// MARK: - Internal

    func loginUser(input: LoginInputModel) -> Observable<Async<Any>> {
        RxAlamofire
            .requestJSON(
                .post,
                loginUrl,
                parameters: input.parameters
            )
            .flatMap { _, json -> Observable<Any> in
                Observable.just(json)
            }
            .async()
   }
}

And then I call this func like this

        interactor.loginUser(input: input)
        .map { (result: Async<Any>) -> LoginStatus in
            switch result {
            case .loading:
                return .loading
            case .success(let data):
                guard let responseModel = TokenModel.parse(from: data) else {
                    return .error
                }
                return .success(responseModel)
            case .error:
                return .error
            }
        }

But the error that is returned gives me very little data. I could use localizedDescription but that would seam like a hack and could possibly change and break the code.

Update

Here is the code for async

extension ObservableType {
public func async() -> Observable<Async<Element>> {
    map {
        Async.success($0)
    }
    .catch { error in
        Observable.just(Async.error(error))
    }
    .do(onCompleted: {
    })
    .startWith(Async.loading)
}
}

and

public enum Async<T> {
case loading
case success(T)
case error(Error)
}
user1898829
  • 3,437
  • 6
  • 34
  • 62

0 Answers0