swagger-api / swagger-api/swagger-codegen
[Swift] Get Status code from error
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
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"
Swagger-codegen version
I am using the current master branch of swagger 2.0. (Code is generated from a spring server.)
Swagger declaration file content or url
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: /
...
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i project.json -l swift3 -o ../project_swagger
Steps to reproduce
Related issues
Suggest a Fix
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?
public typealias ErrorResponse = (Int, Data?, Error?);
/*
public enum ErrorResponse : Error {
case Error(Int, Data?, Error)
}
*/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the swift3 generation command and inspect Models.mustache, especially the ErrorResponse definition used by the generated request callback. Regenerate the client from the supplied Swagger definition and verify that callers can obtain the HTTP status code from an error without the tuple-pattern failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100