vadymmarkov / Malibu

:surfer: Malibu is a networking library built on promises

Home Page:https://vadymmarkov.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The operation couldn’t be completed. (Malibu.NetworkError error 4.)

guilhermearaujo opened this issue · comments

I am trying to run the first example:

let request = Request.get("http://sharkywaters.com/api/boards", parameters: ["type": 1])

// Make a call
Malibu.request(request)
  .validate()
  .toJsonDictionary()
  .done({ boards in
    // Handle response data
    print("done")
  })
  .fail({ error in
    // Handle errors
    print("fail \(error.localizedDescription)")
  })
  .always({ _ in
    // Hide progress bar
    print("always")
  })

and it always fails with the message The operation couldn’t be completed. (Malibu.NetworkError error 4.). What am I doing wrong?

@guilhermearaujo If you're trying to GET http://sharkywaters.com/api/boards it's a fake URL used as example only. You can try playground https://github.com/hyperoslo/Malibu/blob/master/Playground-iOS.playground/Contents.swift instead.

Oops, I actually used an existing URL, just forgot to change in the code above.

I ran the Playground and it worked. But in its examples it always use the Networking method.
Compare these two tests:

// Test One
enum Endpoint: RequestConvertible {
  case fetch

  static let baseUrl: URLStringConvertible = "https://github.com"

  static var headers: [String : String] {
    return [:]
  }

  var request: Request {
    return Request.get("/")
  }
}

let networking = Networking<Endpoint>()
networking.request(.fetch)
  .validate()
  .done({ wave in
    print("Success One")
  })
  .fail({ error in
    print("Error One \(error) - \(error.localizedDescription)")
  })

// Test Two
let request = Request.get("https://github.com/")
Malibu.request(request)
  .validate()
  .done({ wave in
    print("Success Two")
  })
  .fail({ error in
    print("Error Two \(error) - \(error.localizedDescription)")
  })

They're both sending a GET request to the same route, with the same params, headers, etc (at least I thought so), but the first test ends with success, while the second fails, immediately, in fact:

Error Two invalidRequestURL - The operation couldn’t be completed. (Malibu.NetworkError error 4.)
Success One

Using Charles to read the network traffic I can confirm that the second test doesn't even try to reach that route, the request simply doesn't start.

Yes, it seems like there is a bug with AnyEndpoint. It could be fixed by making baseUrl to be optional in RequestConvertible, which actually makes sense I guess.