Skip to content

Commit

Permalink
feat: Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmichaelchen committed Jan 13, 2024
1 parent 87fea10 commit bbde670
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions cmd/svc/org/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ func (s *Service) CreateOrg(

err := org.Insert(ctx, s.db, boil.Infer())
if err != nil {
return nil, fmt.Errorf("unable to insert record: %w", err)
log.Error("Failed to create Org",
"id", req.Msg.GetId(),
"err", err,
)

return nil, connect.NewError(
connect.CodeInternal,
fmt.Errorf("unable to insert record: %w", err),
)
}

log.Info("Successfully created Org.",
"id", req.Msg.GetId(),
"name", req.Msg.GetName(),
)

res := &orgPB.CreateOrgResponse{}

out := connect.NewResponse(res)
Expand All @@ -65,18 +78,33 @@ func (s *Service) GetOrg(
ctx context.Context,
req *connect.Request[orgPB.GetOrgRequest],
) (*connect.Response[orgPB.GetOrgResponse], error) {
log.Info("Retrieving Org...",
"id", req.Msg.GetId(),
)

record, err := models.FindOrg(ctx, s.db, req.Msg.GetId())
if err != nil {
log.Error("Failed to retrieve Org",
"id", req.Msg.GetId(),
"err", err,
)
if errors.Is(err, sql.ErrNoRows) {

Check failure on line 91 in cmd/svc/org/service/service.go

View workflow job for this annotation

GitHub Actions / lint

if statements should only be cuddled with assignments (wsl)
return nil, connect.NewError(
connect.CodeNotFound,
fmt.Errorf("unable to retrieve item: %w", err),
)
}

return nil, fmt.Errorf("unable to retrieve item: %w", err)
return nil, connect.NewError(
connect.CodeInternal,
fmt.Errorf("unable to retrieve item: %w", err),
)
}

log.Info("Successfully retrieved Org...",
"id", req.Msg.GetId(),
)

return connect.NewResponse(&orgPB.GetOrgResponse{
Org: &orgPB.Org{
Id: record.ID,
Expand Down

0 comments on commit bbde670

Please sign in to comment.