Skip to content

Commit

Permalink
chore(server): add logs on internal error
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Jun 27, 2023
1 parent 6b3ab41 commit 4b79e9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion server/internal/adapter/gql/loader_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/reearth/reearth/server/internal/adapter/gql/gqldataloader"
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/log"
"github.com/reearth/reearthx/util"
)

Expand All @@ -23,7 +24,11 @@ func (c *PluginLoader) Fetch(ctx context.Context, ids []gqlmodel.ID) ([]*gqlmode
return nil, []error{err}
}

res, err := c.usecase.Fetch(ctx, ids2, getOperator(ctx))
op := getOperator(ctx)
log.Infof("TEMP: PluginLoader.Fetch op: %#v", op)
log.Infof("TEMP: PluginLoader.Fetch ids: %v", ids)

res, err := c.usecase.Fetch(ctx, ids2, op)
if err != nil {
return nil, []error{err}
}
Expand Down
7 changes: 6 additions & 1 deletion server/internal/adapter/gql/loader_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth/server/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth/server/internal/usecase/interfaces"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/log"
"github.com/reearth/reearthx/util"
)

Expand All @@ -24,7 +25,11 @@ func (c *PropertyLoader) Fetch(ctx context.Context, ids []gqlmodel.ID) ([]*gqlmo
return nil, []error{err}
}

res, err := c.usecase.Fetch(ctx, ids2, getOperator(ctx))
op := getOperator(ctx)
log.Infof("TEMP: PropertyLoader.Fetch op: %#v", op)
log.Infof("TEMP: PropertyLoader.Fetch ids: %v", ids)

res, err := c.usecase.Fetch(ctx, ids2, op)
if err != nil {
return nil, []error{err}
}
Expand Down
10 changes: 10 additions & 0 deletions server/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func initEcho(ctx context.Context, cfg *ServerConfig) *echo.Echo {

func errorHandler(next func(error, echo.Context)) func(error, echo.Context) {
return func(err error, c echo.Context) {
ctx := c.Request().Context()
if c.Response().Committed {
return
}
Expand All @@ -147,6 +148,15 @@ func errorHandler(next func(error, echo.Context)) func(error, echo.Context) {
err = rerror.ErrNotFound
}

if err := rerror.UnwrapErrInternal(err); err != nil {
au := adapter.GetAuthInfo(ctx)
u := adapter.User(ctx)
op := adapter.Operator(ctx)
c.Echo().Logger.Errorf("AUTH: %#v", au)
c.Echo().Logger.Errorf("USER: %#v", u)
c.Echo().Logger.Errorf("OP: %#v", op)
}

code, msg := errorMessage(err, func(f string, args ...interface{}) {
c.Echo().Logger.Errorf(f, args...)
})
Expand Down
5 changes: 5 additions & 0 deletions server/internal/infrastructure/mongo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/reearth/reearth/server/pkg/builtin"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/plugin"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/rerror"
)
Expand Down Expand Up @@ -76,12 +77,16 @@ func (r *Plugin) FindByIDs(ctx context.Context, ids []id.PluginID) ([]*plugin.Pl
var err error

if len(ids2) > 0 {
log.Infof("TEMP: plugin mongo find by ids %v", ids2)

res, err = r.find(ctx, bson.M{
"id": bson.M{"$in": id.PluginIDsToStrings(ids2)},
})
if err != nil {
return nil, err
}

log.Infof("TEMP: plugin mongo find by ids OK")
}

return res.Concat(b.List()).MapToIDs(ids), nil
Expand Down
6 changes: 6 additions & 0 deletions server/internal/infrastructure/mongo/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth/server/internal/usecase/repo"
"github.com/reearth/reearth/server/pkg/id"
"github.com/reearth/reearth/server/pkg/property"
"github.com/reearth/reearthx/log"
"github.com/reearth/reearthx/mongox"
"github.com/reearth/reearthx/rerror"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -68,6 +69,8 @@ func (r *Property) FindByIDs(ctx context.Context, ids id.PropertyIDList) (proper
return nil, nil
}

log.Infof("TEMP: property mongo find by ids %v", ids)

filter := bson.M{
"id": bson.M{
"$in": ids.Strings(),
Expand All @@ -77,6 +80,9 @@ func (r *Property) FindByIDs(ctx context.Context, ids id.PropertyIDList) (proper
if err != nil {
return nil, err
}

log.Infof("TEMP: property mongo find by ids OK")

return filterProperties(ids, res), nil
}

Expand Down

0 comments on commit 4b79e9d

Please sign in to comment.