forked from sonirico/go-hyperliquid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
37 lines (30 loc) · 840 Bytes
/
errors.go
File metadata and controls
37 lines (30 loc) · 840 Bytes
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
package hyperliquid
import (
"fmt"
"strings"
)
//go:generate easyjson -all
type APIError struct {
Code int `json:"code"`
Message string `json:"msg"`
Data any `json:"data,omitempty"`
}
func (e APIError) Error() string {
return fmt.Sprintf("API error %d: %s", e.Code, e.Message)
}
type ValidationError struct {
Field string
Message string
}
func (e ValidationError) Error() string {
return fmt.Sprintf("validation error on field %s: %s", e.Field, e.Message)
}
// IsWalletDoesNotExistError checks if the error is a "wallet does not exist" error from the API
func IsWalletDoesNotExistError(err error) bool {
if err == nil {
return false
}
errMsg := strings.ToLower(err.Error())
return strings.Contains(errMsg, "does not exist") &&
(strings.Contains(errMsg, "wallet") || strings.Contains(errMsg, "user"))
}