bybit.go.api/handlers/errors.go

25 lines
489 B
Go
Raw Permalink Normal View History

2023-10-30 20:26:54 +02:00
package handlers
2023-11-03 16:29:17 +02:00
import (
"errors"
"fmt"
)
2023-10-30 20:26:54 +02:00
// APIError define API error when response status is 4xx or 5xx
type APIError struct {
Code int64 `json:"retCode"`
Message string `json:"retMsg"`
}
// Error return error code and message
func (e APIError) Error() string {
return fmt.Sprintf("<APIError> code=%d, msg=%s", e.Code, e.Message)
}
// IsAPIError check if e is an API error
func IsAPIError(e error) bool {
2023-11-03 16:29:17 +02:00
var APIError *APIError
ok := errors.As(e, &APIError)
2023-10-30 20:26:54 +02:00
return ok
}