swagger-api / swagger-api/swagger-codegen
Response-data ignored for statuscodes > 299
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When a request fails with e.g. a HTTP 400 and the backend delivers some error-information in the response, the generated Swagger-code will ignore the response-data and just always return the error it gets by Alamofire, showing "Invalid statuscode received".
It would be nice to have Swagger deliver the response-data into the Error-response if there is any.
Swagger-codegen version
2.2.2
Swagger declaration file content or url
responses:
400:
description: "Error in your parameters"
schema:
$ref: '#/definitions/Fault'
definitions:
Fault:
properties:
Code:
description: "ErrorCode"
type: string
Message
description: "ErrorMessage"
type: string
Suggest a Fix
if response.result.isFailure {
var error: Error = ErrorResponse.Error(response.response?.statusCode ?? 500, response.data, response.result.error!);
if let responseData = response.data {
if let jsonDictionary = try? JSONSerialization.jsonObject(with: responseData, options:[]) as? [String : Any] {
error = NSError(domain: "backendError", code: response.response?.statusCode ?? 500, userInfo: jsonDictionary);
}
}
completion(nil, error)
return
}
This is the workaround i currently use: I check if there is anything in the response-data and if so I parse it to json. Now of course this can't be applied to the general as not everybody uses JSONs as response.
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
The issue concerns generated Swift client error handling through Alamofire; no source file or test is named. Start by locating the generated response path for HTTP status codes above 299 and compare the response body with the current ErrorResponse behavior. Done means backend error data is preserved without assuming every response is JSON.
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