Commit 5e016016 authored by Mauro E. Bender's avatar Mauro E. Bender

Close #12 - Validate server responses

parent 1faa9293
......@@ -32,7 +32,7 @@ open class Api {
headers: [String: String]? = nil, completion: @escaping (DataResponse<Any>) -> Void )
{
Alamofire.request( urlForPath( path ).absoluteString, method: method, parameters: parameters,
encoding: encoding, headers: headers ).responseJSON( completionHandler: completion )
encoding: encoding, headers: headers ).validate().responseJSON( completionHandler: completion )
}
open func get( _ path: String, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = URLEncoding.default,
......
......@@ -18,6 +18,7 @@ class ApiTests: QuickSpec {
// Register stubs
stub( matchApiPath( "tests/get", method: .get ), http( 200 ) )
stub( matchApiPath( "tests/delete", method: .delete ), http( 200 ) )
stub( matchApiPath( "tests/unsuccess", method: .get ), http( 403 ) )
}
override func spec() {
......@@ -37,6 +38,17 @@ class ApiTests: QuickSpec {
api.request( .delete, path: "tests/delete" ) { result in done() }
}
}
context("when the server responds with an unsuccessful status") {
it( "should return an error" ) {
waitUntil { done in
api.request( .get, path: "tests/unsuccess" ) { response in
expect ( response.result.isFailure ).to (beTrue())
done()
}
}
}
}
}
describe( "get" ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment