Skip to content

Commit 0540448

Browse files
committed
fix: AccessToken が存在しないとき、エラーの代わりに null を返す
1 parent f681b13 commit 0540448

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

router/v3/bots.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (h *Handlers) CreateBot(c echo.Context) error {
9999
return herror.InternalServerError(err)
100100
}
101101

102-
return c.JSON(http.StatusCreated, formatBotDetail(b, t, make([]uuid.UUID, 0)))
102+
return c.JSON(http.StatusCreated, formatBotDetail(b, t.AccessToken, make([]uuid.UUID, 0)))
103103
}
104104

105105
// GetBot GET /bots/:botID
@@ -108,6 +108,7 @@ func (h *Handlers) GetBot(c echo.Context) error {
108108

109109
if isTrue(c.QueryParam("detail")) {
110110
user := getRequestUser(c)
111+
var accessToken string
111112

112113
// アクセス権確認
113114
if !h.RBAC.IsGranted(user.GetRole(), permission.AccessOthersBot) && b.CreatorID != user.GetID() {
@@ -116,20 +117,19 @@ func (h *Handlers) GetBot(c echo.Context) error {
116117

117118
t, err := h.Repo.GetTokenByID(b.AccessTokenID)
118119
if err != nil {
119-
switch err {
120-
case repository.ErrNotFound:
121-
return herror.HTTPError(http.StatusInternalServerError, "This bot's Access Token has been revoked unexpectedly. Please inform admin about this error.")
122-
default:
120+
if err != repository.ErrNotFound {
123121
return herror.InternalServerError(err)
124122
}
123+
} else {
124+
accessToken = t.AccessToken
125125
}
126126

127127
ids, err := h.Repo.GetParticipatingChannelIDsByBot(b.ID)
128128
if err != nil {
129129
return herror.InternalServerError(err)
130130
}
131131

132-
return c.JSON(http.StatusOK, formatBotDetail(b, t, ids))
132+
return c.JSON(http.StatusOK, formatBotDetail(b, accessToken, ids))
133133
}
134134

135135
return c.JSON(http.StatusOK, formatBot(b))

router/v3/responses.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ type BotDetail struct {
230230
Channels []uuid.UUID `json:"channels"`
231231
}
232232

233-
func formatBotDetail(b *model.Bot, t *model.OAuth2Token, channels []uuid.UUID) *BotDetail {
233+
func formatBotDetail(b *model.Bot, accessToken string, channels []uuid.UUID) *BotDetail {
234234
return &BotDetail{
235235
ID: b.ID,
236236
BotUserID: b.BotUserID,
@@ -243,7 +243,7 @@ func formatBotDetail(b *model.Bot, t *model.OAuth2Token, channels []uuid.UUID) *
243243
UpdatedAt: b.UpdatedAt,
244244
Tokens: BotTokens{
245245
VerificationToken: b.VerificationToken,
246-
AccessToken: t.AccessToken,
246+
AccessToken: optional.New(accessToken, accessToken != ""),
247247
},
248248
Endpoint: b.PostURL,
249249
Privileged: b.Privileged,

0 commit comments

Comments
 (0)