forked from algolia/algoliasearch-client-go
/
errors.go
34 lines (29 loc) · 933 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package algoliasearch
import (
"errors"
"net"
)
var (
NoMoreHitsErr error = errors.New("No more hits")
NoMoreSynonymsErr error = errors.New("No more synonyms")
NoMoreRulesErr error = errors.New("No more rules")
ExhaustionOfTryableHostsErr error = errors.New("All hosts have been contacted unsuccessfully")
)
// NetError is used internally to differente regular error from errors
// following the net.Error interface in order to propagate them with a custom
// message.
type NetError struct {
msg string
isTimeout bool
isTemporary bool
}
func NewNetError(err net.Error, msg string) *NetError {
return &NetError{
msg: msg,
isTimeout: err.Timeout(),
isTemporary: err.Temporary(),
}
}
func (e *NetError) Error() string { return e.msg }
func (e *NetError) Timeout() bool { return e.isTimeout }
func (e *NetError) Temporary() bool { return e.isTemporary }