10000 Handle error in deferred body close · Issue #61 · cobbler/cobblerclient · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Handle error in deferred body close #61
Closed
@SchoolGuy

Description

@SchoolGuy

Is your feature request related to a problem?

As a developer
I want to react to all thrown errors
so that I can do the proper cleanup in case something goes wrong.

Provide a detailed description of the proposed feature

The error that may or may not be produced should be fixed in a way that we return a slice of errors that contains both the error from the function body and the deferred function.

r := fmt.Sprintf("%s\n", string(reqBody))
res, err := c.httpClient.Post(c.config.URL, bodyTypeXML, bytes.NewReader([]byte(r)))
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}

Alternatives you've considered

None

Additional information

Blog article describing the whys and hows: https://trstringer.com/golang-deferred-function-error-handling/

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0