I wasn't able to get the status code after making a request. My approach was:
let request = UserdetailcontrollerAPI.createUsingPOST2WithRequestBuilder(userInfo: userInfo);
request.execute {response, error in
if(error != nil){
let err = error as! ErrorResponse
print(err)
switch(error!){
case (409,_,_): print("409");
}
}
Since error is of type Error? I get a "Tuple pattern cannot match values of the non-tuple type: Error"
I am using the current master branch of swagger 2.0. (Code is generated from a spring server.)
```yaml
swagger: '2.0'
info:
description: Api Documentation
version: '1.0'
title: Api Documentation
termsOfService: 'urn:tos'
contact: {}
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0'
host: 'localhost:8080'
basePath: /
...
```
java -jar swagger-codegen-cli.jar generate -i project.json -l swift3 -o ../project_swagger
I needed this immediately so I changed the type of ErrorResponse to in Models.mustache. I don't understand the idea of the original code anyhow. Maybe someone can explain it?
```swift
public typealias ErrorResponse = (Int, Data?, Error?);
/*
public enum ErrorResponse : Error {
case Error(Int, Data?, Error)
}
*/
@jannhendrik can you please confirm you're using the latest master to generate the Swift API client?
cc @jaz-ah @Edubits
@wing328 Yes I was using the current master branch. Sorry for late answer.
@jannhendrik looks like you want switch(err) not switch(error)
That would not make a difference... ErrorResponse still inherits Error, which is not a tuple and thus can not be switched in that form.
This works in v2.2.2 in swift3:
if let err = error as? ErrorResponse {
switch(err){
case .Error(409, _, _): print("409");
}
}
@btaitelb what's the error you get then at this point in master with that same code?
@jaz-ah sorry, I wasn't clear in my comment. I meant that this compiles and runs correctly without error on master. I found this thread by googling how to deal with the ErrorResponse, so figured it could use a working example.
Most helpful comment
This works in v2.2.2 in swift3: