47 lines
950 B
Go
47 lines
950 B
Go
package protocol
|
|
|
|
// ErrorBody 是 resp / 注册失败里的 error 对象。
|
|
type ErrorBody struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// Error 是协议包校验失败时返回的错误,Code 对应第 6.10 节。
|
|
type Error struct {
|
|
Code string
|
|
Message string
|
|
}
|
|
|
|
func (e *Error) Error() string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
if e.Message == "" {
|
|
return e.Code
|
|
}
|
|
return e.Code + ": " + e.Message
|
|
}
|
|
|
|
func (e *Error) Body() ErrorBody {
|
|
if e == nil {
|
|
return ErrorBody{}
|
|
}
|
|
return ErrorBody{Code: e.Code, Message: e.Message}
|
|
}
|
|
|
|
func badRequest(msg string) *Error {
|
|
return &Error{Code: CodeBadRequest, Message: msg}
|
|
}
|
|
|
|
func bodyTooLarge(msg string) *Error {
|
|
return &Error{Code: CodeBodyTooLarge, Message: msg}
|
|
}
|
|
|
|
func metaTooLarge(msg string) *Error {
|
|
return &Error{Code: CodeMetaTooLarge, Message: msg}
|
|
}
|
|
|
|
func frameTooLarge(msg string) *Error {
|
|
return &Error{Code: CodeFrameTooLarge, Message: msg}
|
|
}
|