This commit is contained in:
Daniel Ponte 2022-12-20 20:34:53 -05:00
parent 6443443c6b
commit 6bd36a59c5
3 changed files with 16 additions and 16 deletions

View file

@ -293,7 +293,6 @@ func (a *authenticator) ValidateAccessToken(token AccessToken) *RefreshToken {
return nil return nil
} }
return uvIssRT return uvIssRT
} }

View file

@ -80,9 +80,9 @@ func (b *Blas) Components() components.ComponentStore { return b.components }
func New(cfg *config.Config) (b *Blas, err error) { func New(cfg *config.Config) (b *Blas, err error) {
b = &Blas{ b = &Blas{
Bus: bus.New(), Bus: bus.New(),
Config: cfg, Config: cfg,
components: make(components.ComponentStore), components: make(components.ComponentStore),
WebSocketManager: wsapi.NewManager(), WebSocketManager: wsapi.NewManager(),
} }

View file

@ -16,7 +16,7 @@ import (
var ( var (
NoSuchHandlerErr = errors.New("bad websocket command") NoSuchHandlerErr = errors.New("bad websocket command")
NoMessageIDErr = errors.New("no message ID") NoMessageIDErr = errors.New("no message ID")
) )
type Type string type Type string
@ -122,28 +122,29 @@ type cmdMsg struct {
} }
type MsgType string type MsgType string
const ( const (
ResultMsgType MsgType = "result" ResultMsgType MsgType = "result"
) )
type Error struct { type Error struct {
Code string `json:"code"` Code string `json:"code"`
Message string `json:"message"` Message string `json:"message"`
} }
type WSError struct { type WSError struct {
ID *int `json:"id,omitempty"` ID *int `json:"id,omitempty"`
Type MsgType `json:"type"` Type MsgType `json:"type"`
Success bool `json:"success"` Success bool `json:"success"`
Error Error `json:"error"` Error Error `json:"error"`
} }
func (ws *cmdHandler) writeError(id int, err Error) error { func (ws *cmdHandler) writeError(id int, err Error) error {
return ws.WriteJSON(WSError{ return ws.WriteJSON(WSError{
ID: &id, ID: &id,
Type: ResultMsgType, Type: ResultMsgType,
Success: false, Success: false,
Error: err, Error: err,
}) })
} }
@ -163,10 +164,10 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error {
if !ok { if !ok {
return ws.WriteJSON( return ws.WriteJSON(
WSError{ WSError{
Type: ResultMsgType, Type: ResultMsgType,
Success: false, Success: false,
Error: Error{ Error: Error{
Code: "invalid_id", Code: "invalid_id",
Message: "command has no ID", Message: "command has no ID",
}, },
}) })
@ -181,7 +182,7 @@ func (ws *cmdHandler) handleMsg(r io.Reader) error {
case nil: case nil:
case NoSuchHandlerErr: case NoSuchHandlerErr:
return ws.writeError(id, Error{ return ws.writeError(id, Error{
Code: "invalid_type", Code: "invalid_type",
Message: "no such command", Message: "no such command",
}) })
default: default: