fixes for safe conversation and avoid panics (#1213)
* fixes for safe convertation Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * fix client publish panic If broker connect returns error we dont check it status and use it later to publish message, mostly this is unexpected because broker connection failed and we cant use it. Also proposed solution have benefit - we flag connection status only when we have succeseful broker connection Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org> * api/handler/broker: fix possible broker publish panic Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -25,13 +25,17 @@ func (c *Codec) ReadBody(b interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return proto.Unmarshal(buf, b.(proto.Message))
|
||||
m, ok := b.(proto.Message)
|
||||
if !ok {
|
||||
return codec.ErrInvalidMessage
|
||||
}
|
||||
return proto.Unmarshal(buf, m)
|
||||
}
|
||||
|
||||
func (c *Codec) Write(m *codec.Message, b interface{}) error {
|
||||
p, ok := b.(proto.Message)
|
||||
if !ok {
|
||||
return nil
|
||||
return codec.ErrInvalidMessage
|
||||
}
|
||||
buf, err := proto.Marshal(p)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user