Skip to content

Commit

Permalink
Merge pull request #42 from claustra01/feat/expired-message
Browse files Browse the repository at this point in the history
セッション切れ時のメッセージの追加
  • Loading branch information
claustra01 authored Apr 29, 2024
2 parents 5f49fd3 + ab61333 commit 5b62ad8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bot/google/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"time"
)

var (
ErrCalenderExpired = errors.New("calender api session expired")
)

type CalendarContentInterface interface {
GetType() string
}
Expand Down Expand Up @@ -98,7 +102,9 @@ func (c *OAuthClient) RegisterCalenderEvent(content CalendarContent, accessToken
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
if resp.StatusCode == http.StatusUnauthorized {
return ErrCalenderExpired
} else if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Failed to register event: %s", resp.Status)
}

Expand Down
30 changes: 30 additions & 0 deletions bot/handler/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ func Callback(w http.ResponseWriter, req *http.Request, bot *linebot.LineBot) {
}

err = googleClient.RegisterCalenderEvent(content, accessToken)
if err == google.ErrCalenderExpired {
log.Printf("Failed to register event: %+v\n", err)
replyText := fmt.Sprintf("セッション切れです。再度ログインしてください。\n%s", liffUrl)
_, err = bot.ReplyMessage(
&linebot.ReplyMessageRequest{
ReplyToken: e.ReplyToken,
Messages: []linebot.MessageInterface{
linebot.NewTextMessage(replyText),
},
},
)
if err != nil {
log.Print(err)
}
}
if err != nil {
log.Printf("Failed to register event: %+v\n", err)
_, err = bot.ReplyMessage(
Expand Down Expand Up @@ -328,6 +343,21 @@ func Callback(w http.ResponseWriter, req *http.Request, bot *linebot.LineBot) {
}

err = googleClient.RegisterCalenderEvent(content, accessToken)
if err == google.ErrCalenderExpired {
log.Printf("Failed to register event: %+v\n", err)
replyText := fmt.Sprintf("セッション切れです。再度ログインしてください。\n%s", liffUrl)
_, err = bot.ReplyMessage(
&linebot.ReplyMessageRequest{
ReplyToken: e.ReplyToken,
Messages: []linebot.MessageInterface{
linebot.NewTextMessage(replyText),
},
},
)
if err != nil {
log.Print(err)
}
}
if err != nil {
log.Printf("Failed to register event: %+v\n", err)
_, err = bot.ReplyMessage(
Expand Down

0 comments on commit 5b62ad8

Please sign in to comment.