Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handling #4

Closed
astropanic opened this issue Jun 27, 2015 · 3 comments
Closed

error handling #4

astropanic opened this issue Jun 27, 2015 · 3 comments

Comments

@astropanic
Copy link

Is there a reason why this library doesn't provide the "go way" of error handling ?

resp := grequests.Get("http://httpbin.org/xml", nil)

if resp.Error != nil {
    log.Fatalln("Unable to make request", resp.Error)
}

VS

resp, err := grequests.Get("http://httpbin.org/xml", nil)

if err != nil {
    log.Fatalln("Unable to make request", err)
}
@ShawnMilo
Copy link

The standard library uses both methods. The second is more common, but Scanner.Scan() in the bufio package does it the first way.

You read each line in the file, and at the end you check if your scanner's .Err is something you care about.

@levigross
Copy link
Owner

The resp.Error pattern is a remnant of the asynchronous nature of the library (up until a few days ago all functions returned a channel).

I do intend to make to change the API to the more "standard" way

resp, err := grequests.Get("http://httpbin.org/xml", nil)

if err != nil {
    log.Fatalln("Unable to make request", err)
}

@levigross
Copy link
Owner

Fixed in #0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants