Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure program doesn't crash when delete fails #51

Merged
merged 1 commit into from
May 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions room/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var (
ErrLackingCapabilities = errors.New("lacking required capabilities")
// ErrForbidden is returned if the user is forbidden from accessing the requested resource
ErrForbidden = errors.New("request forbidden")
// ErrUnexpectedResponse is returned if the response from the Nextcloud Talk server is not formatted as expected
ErrUnexpectedResponse = errors.New("unexpected response")
)

// TalkRoom represents a room in Nextcloud Talk
Expand Down Expand Up @@ -118,10 +120,16 @@ func (t *TalkRoom) DeleteMessage(messageID int) (*ocs.TalkRoomMessageData, error
if err != nil {
return nil, err
}
if res.StatusCode() != http.StatusOK && res.StatusCode() != http.StatusAccepted {
return nil, ErrUnexpectedReturnCode
}
msgInfo, err := ocs.TalkRoomMessageDataUnmarshal(&res.Data)
if err != nil {
return nil, err
}
if len(msgInfo.OCS.TalkRoomMessage) == 0 {
return nil, ErrUnexpectedResponse
}
return &msgInfo.OCS.TalkRoomMessage[0], nil
}

Expand Down