Files
NixMsg/sdk/go/errors.go
T

47 lines
1.1 KiB
Go

package nixmsg
import "fmt"
// APIError 是带协议错误码的错误。
type APIError struct {
Code string
Message string
}
func (e *APIError) Error() string {
if e.Message == "" {
return e.Code
}
return fmt.Sprintf("%s: %s", e.Code, e.Message)
}
func apiErr(code, msg string) *APIError {
return &APIError{Code: code, Message: msg}
}
// 常用错误码(与 DEVELOPMENT 第 6.10 节一致)。
const (
CodeBodyTooLarge = "body_too_large"
CodeFrameTooLarge = "frame_too_large"
CodeMetaTooLarge = "meta_too_large"
CodeRateLimited = "rate_limited"
CodeBadRequest = "bad_request"
CodeNotReady = "not_ready"
CodeBusy = "busy"
CodeSessionInvalid = "session_invalid"
CodeBadCredentials = "bad_credentials"
CodeQueueFull = "queue_full"
CodeNotConnected = "not_connected"
CodeClosed = "closed"
CodeAuthFailed = "auth_failed"
CodeKicked = "kicked"
)
// AuthReason 是认证失败原因。
type AuthReason string
const (
AuthSessionInvalid AuthReason = "session_invalid"
AuthBadCredentials AuthReason = "bad_credentials"
)