Skip to content

fix(clients): implement Is on custom errors [skip-e2e] #4588

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

Merged
merged 2 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clients/algoliasearch-client-go/algolia/errs/net_err.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ func NetError(err net.Error, msg string) net.Error {
func (e *netError) Error() string { return e.msg }
func (e *netError) Timeout() bool { return e.isTimeout }
func (e *netError) Temporary() bool { return e.isTemporary }

func (e netError) Is(target error) bool {
_, ok := target.(*netError)

return ok
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ func (e *NoMoreHostToTryError) Error() string {
}
return "all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. You can use 'ExposeIntermediateNetworkErrors: true' in the config to investigate."
}


func (n NoMoreHostToTryError) Is(target error) bool {
_, ok := target.(*NoMoreHostToTryError)

return ok
}
18 changes: 18 additions & 0 deletions clients/algoliasearch-client-go/algolia/errs/wait_err.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,32 @@ func (e WaitError) Error() string {
return e.msg
}

func (e WaitError) Is(target error) bool {
_, ok := target.(*WaitError)

return ok
}

type WaitKeyUpdateError struct{}

func (e WaitKeyUpdateError) Error() string {
return "`apiKey` is required when waiting for an `update` operation."
}

func (e WaitKeyUpdateError) Is(target error) bool {
_, ok := target.(*WaitKeyUpdateError)

return ok
}

type WaitKeyOperationError struct{}

func (e WaitKeyOperationError) Error() string {
return "`operation` must be one of `add`, `update` or `delete`."
}

func (e WaitKeyOperationError) Is(target error) bool {
_, ok := target.(*WaitKeyOperationError)

return ok
}
6 changes: 6 additions & 0 deletions templates/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,9 @@ func (o *APIError) UnmarshalJSON(bytes []byte) error {

return nil
}

func (a APIError) Is(target error) bool {
_, ok := target.(*APIError)

return ok
}