Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
totegamma committed Jun 23, 2024
1 parent 833ffb4 commit 5704797
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion x/association/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ func (s *service) Create(ctx context.Context, mode core.CommitMode, document str
if owner.Domain == s.config.FQDN { // signerが自ドメイン管轄の場合、リソースを作成
association, err = s.repo.Create(ctx, association)
if err != nil {
if errors.Is(err, core.ErrorAlreadyExists{}) {
return association, core.NewErrorAlreadyExists()
}
span.RecordError(err)
return association, err // TODO: if err is duplicate key error, server should return 409
return association, err
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/store/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ func (h *handler) Commit(c echo.Context) error {
result, err := h.service.Commit(ctx, core.CommitModeExecute, request.Document, request.Signature, request.Option, keys)
if err != nil {
if errors.Is(err, core.ErrorPermissionDenied{}) {
return c.JSON(http.StatusForbidden, echo.Map{"error": "Permission Denied"})
return c.JSON(http.StatusForbidden, echo.Map{"status": "error", "error": err.Error()})
}
if errors.Is(err, core.ErrorAlreadyExists{}) {
return c.JSON(http.StatusOK, echo.Map{"info": "Already Exists"})
return c.JSON(http.StatusOK, echo.Map{"status": "processed", "content": result})
}
if errors.Is(err, core.ErrorAlreadyDeleted{}) {
return c.JSON(http.StatusOK, echo.Map{"info": "Already Deleted"})
return c.JSON(http.StatusOK, echo.Map{"status": "processed", "content": result})
}

span.RecordError(err)
return c.JSON(http.StatusInternalServerError, echo.Map{"error": err.Error()})
}

return c.JSON(http.StatusCreated, echo.Map{"content": result})
return c.JSON(http.StatusCreated, echo.Map{"status": "ok", "content": result})
}

func (h *handler) Get(c echo.Context) error {
Expand Down

0 comments on commit 5704797

Please sign in to comment.