Skip to content

Commit

Permalink
[GH-129] MS Graph error is shown when selecting acceptance (#138)
Browse files Browse the repository at this point in the history
* Change HasPrefix for Contains

* Use helpers functions

Co-authored-by: Ben Schumacher <[email protected]>
  • Loading branch information
larkox and hanzei authored May 28, 2020
1 parent 95ad6b1 commit 8e4fd89
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/api/post_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (api *api) postActionRespond(w http.ResponseWriter, req *http.Request) {
return
}
err := calendar.RespondToEvent(user, eventID, option)
if err != nil && !strings.HasPrefix(err.Error(), "202") && !strings.HasPrefix(err.Error(), "404") {
if err != nil && !isAcceptedError(err) && !isNotFoundError(err) {
utils.SlackAttachmentError(w, "Error: Failed to respond to event: "+err.Error())
return
}
Expand All @@ -105,7 +105,7 @@ func (api *api) postActionRespond(w http.ResponseWriter, req *http.Request) {

sa := sas[0]

if err == nil || strings.HasPrefix(err.Error(), "202") {
if err == nil || isAcceptedError(err) {
sa.Fields = append(sa.Fields, &model.SlackAttachmentField{
Title: "Response",
Value: fmt.Sprintf("You have %s this event", prettyOption(option)),
Expand All @@ -119,7 +119,7 @@ func (api *api) postActionRespond(w http.ResponseWriter, req *http.Request) {

postResponse.Update = p

if err != nil && strings.HasPrefix(err.Error(), "404") {
if err != nil && isNotFoundError(err) {
postResponse.EphemeralText = "Event has changed since this message. Please change your status directly on MS Calendar."
}
w.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -229,3 +229,11 @@ func getEventInfo(ctx map[string]interface{}) (string, error) {

return views.RenderEventWillStartLine(subject, weblink, startTime), nil
}

func isAcceptedError(err error) bool {
return strings.Contains(err.Error(), "202 Accepted")
}

func isNotFoundError(err error) bool {
return strings.Contains(err.Error(), "404 Not Found")
}

0 comments on commit 8e4fd89

Please sign in to comment.