Skip to content

Commit

Permalink
adding log for api failure and tidy up error type
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCookie95 committed Nov 13, 2024
1 parent 51b7bdd commit 83b964e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (p *Plugin) MattermostAuthorizationRequired(next http.Handler) http.Handler

func (p *Plugin) HelloWorld(w http.ResponseWriter, r *http.Request) {
if _, err := w.Write([]byte("Hello, world!")); err != nil {
p.API.LogError("Failed to write response", "error", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
4 changes: 2 additions & 2 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Handler struct {
}

type Command interface {
Handle(args *model.CommandArgs) (*model.CommandResponse, *model.AppError)
Handle(args *model.CommandArgs) (*model.CommandResponse, error)
executeHelloCommand(args *model.CommandArgs) *model.CommandResponse
}

Expand All @@ -36,7 +36,7 @@ func NewCommandHandler(client *pluginapi.Client) Command {
}

// ExecuteCommand hook calls this method to execute the commands that were registered in the NewCommandHandler function.
func (c *Handler) Handle(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
func (c *Handler) Handle(args *model.CommandArgs) (*model.CommandResponse, error) {
trigger := strings.TrimPrefix(strings.Fields(args.Command)[0], "/")
switch trigger {
case helloCommandTrigger:
Expand Down
7 changes: 6 additions & 1 deletion server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"net/http"
"sync"
"time"

Expand Down Expand Up @@ -71,7 +72,11 @@ func (p *Plugin) OnDeactivate() error {

// This will execute the commands that were registered in the NewCommandHandler function.
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
return p.commandClient.Handle(args)
response, err := p.commandClient.Handle(args)
if err != nil {
return nil, model.NewAppError("ExecuteCommand", "plugin.command.execute_command.app_error", nil, err.Error(), http.StatusInternalServerError)
}
return response, nil
}

// See https://developers.mattermost.com/extend/plugins/server/reference/

0 comments on commit 83b964e

Please sign in to comment.