typesense / typesense-go

Go client for Typesense: https://github.com/typesense/typesense
Apache License 2.0
208 stars 55 forks source link

Is there a way to check the type of error? #146

Closed yothgewalt closed 12 months ago

yothgewalt commented 1 year ago

Description

I don't know how to check the error type, for example, is it 404 or 409 etc.

Now I replace it by using the split function to grab the httpcode and check it.

And I'd like to ask, is there a better way?

Steps to reproduce

Expected Behavior

Actual Behavior

Metadata

Typesense Version:

OS:

vamshiaruru commented 1 year ago
    target := &typesense.HTTPError{} // nolint:exhaustruct
    if errors.As(err, &target) {
        t := *target
        fmt.Println(t.Status, t.Body)
    }
yothgewalt commented 12 months ago
  target := &typesense.HTTPError{} // nolint:exhaustruct
  if errors.As(err, &target) {
      t := *target
      fmt.Println(t.Status, t.Body)
  }

Thank you, Its working!