forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_helpers.go
41 lines (33 loc) · 902 Bytes
/
error_helpers.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
35
36
37
38
39
40
41
package horizonclient
import "github.com/stellar/go/support/errors"
// IsNotFoundError returns true if the error is a horizonclient.Error with
// a not_found problem indicating that the resource is not found on
// Horizon.
func IsNotFoundError(err error) bool {
var hErr *Error
err = errors.Cause(err)
switch err := err.(type) {
case *Error:
hErr = err
case Error:
hErr = &err
}
if hErr == nil {
return false
}
return hErr.Problem.Type == "https://stellar.org/horizon-errors/not_found"
}
// GetError returns an error that can be interpreted as a horizon-specific
// error. If err cannot be interpreted as a horizon-specific error, a nil error
// is returned. The caller should still check whether err is nil.
func GetError(err error) *Error {
var hErr *Error
err = errors.Cause(err)
switch e := err.(type) {
case *Error:
hErr = e
case Error:
hErr = &e
}
return hErr
}