Skip to content

Add a dedicated guide on error handling (err vs res.IsError()) #1062

@eduardolat

Description

@eduardolat

Hey folks, first off, awesome library!

I'm opening this issue to suggest a documentation improvement. I think it would be super helpful for new users to have a dedicated page on resty.dev (and maybe linked in the README) that's all about error handling.

For a beginner, it can be pretty confusing to figure out the difference between the two main ways an error can happen.

  1. The err returned from the request:

    res, err := client.R().Get("https://example.com")
    if err != nil {
      // What kind of error is this? (e.g., connection failed, DNS, timeout)
    }
  2. The res.IsError() check:

    if res.IsError() {
      // And what kind of error is this? (e.g., 404, 500)
    }

A new user might see err == nil and assume everything worked, but they might have actually received a 500 Internal Server Error. Or, they might get a connection error where err != nil, and then try to check res.IsError()

Having a "Error Handling" page would be amazing. It could clearly explain:

  • When err will be non-nil (client-side problems, connection issues, timeouts, marshalling errors, etc.).
  • When res.IsError() will be true (server-side problems, 4xx/5xx status codes).
  • The recommended "best practice" way to check for both conditions to safely handle all possible errors.
  • Basically, a guide for everything related to errors

I think this would clear up a lot of confusion and help people get started more smoothly.

Thanks for considering it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions