我正在使用 RxAlamorefire 在我的应用程序中处理网络任务。
我的问题是:当我发出请求并返回 json。如果 json 有一个关键的“错误”,我需要发出错误通知而不是 onNext 通知。
我的代码是这样的:
let observable = RxAlamofire.json(.get, url, parameters: nil, encoding: URLEncoding.default, headers: header)
.map { (json) -> SomeObject? in
//Should check json maybe not in ".map" to see if the json contain "error" then emit onError notification.
return Mapper<SomeObject>().map(JSONObject: json)
}