Skip to content

Commit

Permalink
Merge pull request #519 from traPtitech/remove_http
Browse files Browse the repository at this point in the history
remove zapHTTP
  • Loading branch information
wtks authored Mar 19, 2019
2 parents dc9b5ab + c53211a commit 112bd6b
Show file tree
Hide file tree
Showing 19 changed files with 173 additions and 187 deletions.
4 changes: 2 additions & 2 deletions router/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func (h *Handlers) GetActivityLatestMessages(c echo.Context) error {

messages, err := h.Repo.GetChannelLatestMessagesByUserID(userID, req.Limit, req.SubscribeOnly)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

reports, err := h.Repo.GetMessageReportsByReporterID(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
hidden := make(map[uuid.UUID]bool)
Expand Down
26 changes: 13 additions & 13 deletions router/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (h *Handlers) GetChannels(c echo.Context) error {

channelList, err := h.Repo.GetChannelsByUserID(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -60,7 +60,7 @@ func (h *Handlers) GetChannels(c echo.Context) error {
// プライベートチャンネルのメンバー取得
member, err := h.Repo.GetPrivateChannelMemberIDs(ch.ID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
entry.Member = member
Expand Down Expand Up @@ -126,7 +126,7 @@ func (h *Handlers) PostChannels(c echo.Context) error {
case repository.ErrChannelDepthLimitation:
return echo.NewHTTPError(http.StatusBadRequest, err)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -142,15 +142,15 @@ func (h *Handlers) PostChannels(c echo.Context) error {
case repository.ErrChannelDepthLimitation:
return echo.NewHTTPError(http.StatusBadRequest, err)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
}

formatted, err := h.formatChannel(ch)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
return c.JSON(http.StatusCreated, formatted)
Expand All @@ -162,7 +162,7 @@ func (h *Handlers) GetChannelByChannelID(c echo.Context) error {

formatted, err := h.formatChannel(ch)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
return c.JSON(http.StatusOK, formatted)
Expand All @@ -189,15 +189,15 @@ func (h *Handlers) PatchChannelByChannelID(c echo.Context) error {
case repository.ErrForbidden:
return echo.NewHTTPError(http.StatusForbidden)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
}

if req.Force != nil || req.Visibility != nil {
if err := h.Repo.UpdateChannelAttributes(channelID, req.Visibility, req.Force); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -227,14 +227,14 @@ func (h *Handlers) PostChannelChildren(c echo.Context) error {
case repository.ErrChannelDepthLimitation:
return echo.NewHTTPError(http.StatusBadRequest, err)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}

formatted, err := h.formatChannel(ch)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
return c.JSON(http.StatusCreated, formatted)
Expand All @@ -260,7 +260,7 @@ func (h *Handlers) PutChannelParent(c echo.Context) error {
case repository.ErrForbidden:
return echo.NewHTTPError(http.StatusForbidden)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -273,7 +273,7 @@ func (h *Handlers) DeleteChannelByChannelID(c echo.Context) error {
channelID := getRequestParamAsUUID(c, paramChannelID)

if err := h.Repo.DeleteChannel(channelID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down Expand Up @@ -301,7 +301,7 @@ func (h *Handlers) PutTopic(c echo.Context) error {
}

if err := h.Repo.UpdateChannelTopic(channelID, req.Text, userID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down
24 changes: 12 additions & 12 deletions router/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (h *Handlers) GetMyTokens(c echo.Context) error {

ot, err := h.OAuth2.GetTokensByUser(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -62,7 +62,7 @@ func (h *Handlers) GetMyTokens(c echo.Context) error {
case oauth2.ErrClientNotFound:
continue
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (h *Handlers) DeleteMyToken(c echo.Context) error {
case oauth2.ErrTokenNotFound:
return echo.NewHTTPError(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -104,7 +104,7 @@ func (h *Handlers) DeleteMyToken(c echo.Context) error {
case oauth2.ErrTokenNotFound:
return echo.NewHTTPError(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -118,7 +118,7 @@ func (h *Handlers) GetClients(c echo.Context) error {

oc, err := h.OAuth2.GetClientsByUser(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (h *Handlers) PostClients(c echo.Context) error {
Scopes: scopes,
}
if err := h.OAuth2.SaveClient(client); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -197,7 +197,7 @@ func (h *Handlers) GetClient(c echo.Context) error {
case oauth2.ErrClientNotFound:
return echo.NewHTTPError(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -221,7 +221,7 @@ func (h *Handlers) PatchClient(c echo.Context) error {
case oauth2.ErrClientNotFound:
return echo.NewHTTPError(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ func (h *Handlers) PatchClient(c echo.Context) error {
}

if err := h.OAuth2.UpdateClient(oc); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -275,7 +275,7 @@ func (h *Handlers) DeleteClient(c echo.Context) error {
case oauth2.ErrClientNotFound:
return echo.NewHTTPError(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -285,13 +285,13 @@ func (h *Handlers) DeleteClient(c echo.Context) error {

// revoke tokens
if err := h.OAuth2.DeleteTokenByClient(clientID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

// delete client
if err := h.OAuth2.DeleteClient(clientID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down
28 changes: 14 additions & 14 deletions router/clips.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (h *Handlers) GetClips(c echo.Context) error {
// クリップ取得
clips, err := h.Repo.GetClipMessagesByUser(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func (h *Handlers) PostClip(c echo.Context) error {
case repository.ErrNotFound:
return echo.NewHTTPError(http.StatusBadRequest, "the folder is not found")
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -80,7 +80,7 @@ func (h *Handlers) PostClip(c echo.Context) error {
// 指定されていない場合はデフォルトフォルダを探す
folders, err := h.Repo.GetClipFolders(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
for _, v := range folders {
Expand All @@ -93,7 +93,7 @@ func (h *Handlers) PostClip(c echo.Context) error {
// 存在しなかったのでデフォルトフォルダを作る
folder, err := h.Repo.CreateClipFolder(userID, "Default")
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
req.FolderID = folder.ID.String()
Expand All @@ -106,7 +106,7 @@ func (h *Handlers) PostClip(c echo.Context) error {
if isMySQLDuplicatedRecordErr(err) {
return echo.NewHTTPError(http.StatusBadRequest, "already clipped")
}
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -127,7 +127,7 @@ func (h *Handlers) DeleteClip(c echo.Context) error {

// クリップ削除
if err := h.Repo.DeleteClip(clipID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -145,7 +145,7 @@ func (h *Handlers) GetClipsFolder(c echo.Context) error {
case repository.ErrNotFound:
return c.NoContent(http.StatusNotFound)
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return c.NoContent(http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (h *Handlers) PutClipsFolder(c echo.Context) error {
case repository.ErrNotFound:
return echo.NewHTTPError(http.StatusBadRequest, "the folder is not found")
default:
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}
}
Expand All @@ -184,7 +184,7 @@ func (h *Handlers) PutClipsFolder(c echo.Context) error {

// クリップを更新
if err := h.Repo.ChangeClipFolder(clipID, folder.ID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -198,7 +198,7 @@ func (h *Handlers) GetClipFolders(c echo.Context) error {
// フォルダ取得
folders, err := h.Repo.GetClipFolders(userID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -224,7 +224,7 @@ func (h *Handlers) PostClipFolder(c echo.Context) error {
// フォルダ名が重複
return echo.NewHTTPError(http.StatusConflict, "the name is duplicated")
}
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -244,7 +244,7 @@ func (h *Handlers) GetClipFolder(c echo.Context) error {
// クリップ取得
clips, err := h.Repo.GetClipMessages(folder.ID)
if err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down Expand Up @@ -279,7 +279,7 @@ func (h *Handlers) PatchClipFolder(c echo.Context) error {
// フォルダ名が重複
return echo.NewHTTPError(http.StatusConflict, "the name is duplicated")
}
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand All @@ -292,7 +292,7 @@ func (h *Handlers) DeleteClipFolder(c echo.Context) error {

// フォルダ削除
if err := h.Repo.DeleteClipFolder(folderID); err != nil {
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err), zapHTTP(c))
h.requestContextLogger(c).Error(unexpectedError, zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError)
}

Expand Down
Loading

0 comments on commit 112bd6b

Please sign in to comment.