Skip to content

[Golang][client] client.decode error is not handled  #1287

@grokify

Description

@grokify
Description

When StatusCode < 300, a.client.decode returns an error but it is not handled in the code which returns a nil error. There is a comment that mentions some kind of handling that is necessary but the handling doesn't exist.

if localVarHttpResponse.StatusCode < 300 {
// If we succeed, return the data, otherwise pass on to decode error.
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err == nil {
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
}
}

However, the error is not handled and the next thing that happens is that error is returned as a nil at the end of the function:

return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, nil

openapi-generator version

master: 8507916

OpenAPI declaration file content or url

n/a

Command line used for generation

n/a

Steps to reproduce

Make an API call that generates a decode error, e.g. if model schema doesn't return what is returned by the API.

Related issues/PRs

n/a

Suggest a fix/enhancement

Implement GenericOpenAPIError similar to when StatusCode >= 300 with GenericOpenAPIError.

if localVarHttpResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
error: localVarHttpResponse.Status,
}
{{#responses}}
{{#dataType}}
if localVarHttpResponse.StatusCode == {{{code}}} {
var v {{{dataType}}}
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, newErr
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions