Skip to content

Commit

Permalink
Log service call failures
Browse files Browse the repository at this point in the history
  • Loading branch information
dansimau committed Dec 24, 2024
1 parent 73fc18c commit bc5f417
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions hassws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,9 @@ func (c *Client) CallService(msg CallServiceRequest) (CallServiceResponse, error
return CallServiceResponse{}, err
}

if resp.Type == MessageTypeResult && !resp.Success {
slog.Error("Call service failed", "err", resp.Error)
}

return resp, nil
}
3 changes: 2 additions & 1 deletion hassws/message_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type EventMessage struct {
type subscribeEventsRequest struct {
ID int `json:"id"`
Type MessageType `json:"type"`
EventType string `json:"event_type"`
EventType string `json:"event_type,omitempty"`
}

type subscribeEventsResponse struct {
Expand All @@ -79,6 +79,7 @@ type CallServiceResponse struct {
ID string `json:"id"`
} `json:"context"`
} `json:"result"`
Error map[string]any `json:"error,omitempty"`
}

type jsonMessage map[string]any
2 changes: 1 addition & 1 deletion hassws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (s *Server) listen() {
Success: true,
})
default:
panic("[Server]Unknown message type: " + cmd.Type)
panic("[Server] Unknown message type: " + cmd.Type)
}
}
}
Expand Down

0 comments on commit bc5f417

Please sign in to comment.