Skip to content

Commit 7e5e124

Browse files
authored
fix(clients): implement Is on custom errors (#4588)
## 🧭 What and Why This allow users to use `errors.Is` on our custom errors
1 parent 4f67cd0 commit 7e5e124

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

clients/algoliasearch-client-go/algolia/errs/net_err.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ func NetError(err net.Error, msg string) net.Error {
2121
func (e *netError) Error() string { return e.msg }
2222
func (e *netError) Timeout() bool { return e.isTimeout }
2323
func (e *netError) Temporary() bool { return e.isTemporary }
24+
25+
func (e netError) Is(target error) bool {
26+
_, ok := target.(*netError)
27+
28+
return ok
29+
}

clients/algoliasearch-client-go/algolia/errs/no_more_host_to_try_err.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ func (e *NoMoreHostToTryError) Error() string {
2727
}
2828
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."
2929
}
30+
31+
32+
func (n NoMoreHostToTryError) Is(target error) bool {
33+
_, ok := target.(*NoMoreHostToTryError)
34+
35+
return ok
36+
}

clients/algoliasearch-client-go/algolia/errs/wait_err.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,32 @@ func (e WaitError) Error() string {
1414
return e.msg
1515
}
1616

17+
func (e WaitError) Is(target error) bool {
18+
_, ok := target.(*WaitError)
19+
20+
return ok
21+
}
22+
1723
type WaitKeyUpdateError struct{}
1824

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

29+
func (e WaitKeyUpdateError) Is(target error) bool {
30+
_, ok := target.(*WaitKeyUpdateError)
31+
32+
return ok
33+
}
34+
2335
type WaitKeyOperationError struct{}
2436

2537
func (e WaitKeyOperationError) Error() string {
2638
return "`operation` must be one of `add`, `update` or `delete`."
2739
}
40+
41+
func (e WaitKeyOperationError) Is(target error) bool {
42+
_, ok := target.(*WaitKeyOperationError)
43+
44+
return ok
45+
}

templates/go/client.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,9 @@ func (o *APIError) UnmarshalJSON(bytes []byte) error {
390390

391391
return nil
392392
}
393+
394+
func (a APIError) Is(target error) bool {
395+
_, ok := target.(*APIError)
396+
397+
return ok
398+
}

0 commit comments

Comments
 (0)