Advertisement
McFamous

Untitled

Jan 25th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. func getChargingPoints() -> Single<Result<[ChargingPoint<Connector>], ApiError>> {
  2. authInterceptor.isEnabled = false
  3. return gateProvider.rx
  4. .request(.getChargingPoints)
  5. .flatMap({ response in
  6. self.authInterceptor.isEnabled = true
  7. if response.isSuccessful {
  8. guard let chargingPointsApi = try? response.map(GateApiResponse<ArrayPayload<ChargingPointApi>>.self) else {
  9. DDLogError("Mapping error")
  10. return Single.just(.failure(.unexpectedError))
  11. }
  12. let chargingPoints = chargingPointsApi.payload?.items.map { return $0.toChargingPoint() } ?? []
  13. DDLogInfo("Successful response")
  14. return Single.just(.success(chargingPoints))
  15. } else {
  16. guard let error = try? response.map(GateApiResponse<[ChargingPointApi]>.self).toNetworkError() else {
  17. DDLogError("Response error: \(response.description)")
  18. return Single.just(.failure(.unexpectedError))
  19. }
  20. DDLogError("Response error: \(error.statusCode) - \(error.description)")
  21. return Single.just(.failure(.unexpectedError))
  22. }
  23. })
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement