mirror of
https://github.com/mochi-mqtt/server.git
synced 2025-11-03 10:31:11 +08:00
Now when a "publish" command fails, then the publish method will throw an error (#229)
Errors in the hook when doing a publish were ignored. This caused that test cases could not be made where the publish failed and an error was thrown. Co-authored-by: hector.oliveros@wabtec.com <hectoroliveros@MacBook-Pro-de-Hector.local>
This commit is contained in:
11
hooks.go
11
hooks.go
@@ -374,13 +374,14 @@ func (h *Hooks) OnPublish(cl *Client, pk packets.Packet) (pkx packets.Packet, er
|
|||||||
for _, hook := range h.GetAll() {
|
for _, hook := range h.GetAll() {
|
||||||
if hook.Provides(OnPublish) {
|
if hook.Provides(OnPublish) {
|
||||||
npk, err := hook.OnPublish(cl, pkx)
|
npk, err := hook.OnPublish(cl, pkx)
|
||||||
if err != nil && errors.Is(err, packets.ErrRejectPacket) {
|
if err != nil {
|
||||||
h.Log.Debug().Err(err).Str("hook", hook.ID()).Interface("packet", pkx).Msg("publish packet rejected")
|
if errors.Is(err, packets.ErrRejectPacket) {
|
||||||
|
h.Log.Debug().Err(err).Str("hook", hook.ID()).Interface("packet", pkx).Msg("publish packet rejected")
|
||||||
|
return pk, err
|
||||||
|
}
|
||||||
|
h.Log.Error().Err(err).Str("hook", hook.ID()).Interface("packet", pkx).Msg("publish packet error")
|
||||||
return pk, err
|
return pk, err
|
||||||
} else if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pkx = npk
|
pkx = npk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ func TestHooksOnPublish(t *testing.T) {
|
|||||||
// coverage: failure
|
// coverage: failure
|
||||||
hook.fail = true
|
hook.fail = true
|
||||||
pk, err = h.OnPublish(new(Client), packets.Packet{PacketID: 10})
|
pk, err = h.OnPublish(new(Client), packets.Packet{PacketID: 10})
|
||||||
require.NoError(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, uint16(10), pk.PacketID)
|
require.Equal(t, uint16(10), pk.PacketID)
|
||||||
|
|
||||||
// coverage: reject packet
|
// coverage: reject packet
|
||||||
|
|||||||
Reference in New Issue
Block a user