diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2023-11-27 13:05:09 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-27 13:05:09 -0800 |
| commit | d0ba21fc13154c2ffc95829cd064a8e804ea93e3 (patch) | |
| tree | b343092f34f9052501030e2a43f37813e6471587 /hotline | |
| parent | 931031276f4a663b61abaa2e5207740565de8351 (diff) | |
Add missing error handling and logging (#109)
Diffstat (limited to 'hotline')
| -rw-r--r-- | hotline/transaction_handlers.go | 7 | ||||
| -rw-r--r-- | hotline/transaction_handlers_test.go | 2 |
2 files changed, 6 insertions, 3 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 5de2b45..85f85a4 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -305,7 +305,7 @@ func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err erro func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) { if !cc.Authorize(accessSendPrivMsg) { res = append(res, cc.NewErrReply(t, "You are not allowed to send private messages.")) - return res, err + return res, errors.New("user is not allowed to send private messages") } msg := t.GetField(FieldData) @@ -326,7 +326,10 @@ func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, er reply.Fields = append(reply.Fields, NewField(FieldQuotingMsg, t.GetField(FieldQuotingMsg).Data)) } - id, _ := byteToInt(ID.Data) + id, err := byteToInt(ID.Data) + if err != nil { + return res, errors.New("invalid client ID") + } otherClient, ok := cc.Server.Clients[uint16(id)] if !ok { return res, errors.New("invalid client ID") diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 01880f2..525bb88 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -2438,7 +2438,7 @@ func TestHandleSendInstantMsg(t *testing.T) { }, }, }, - wantErr: assert.NoError, + wantErr: assert.Error, }, { name: "when client 1 sends a message to client 2", |