From 570479752c0dd29a21332cf25cc8ea5b2685cbe0 Mon Sep 17 00:00:00 2001 From: totegamma Date: Sun, 23 Jun 2024 23:18:06 +0900 Subject: [PATCH] small fix --- x/association/service.go | 5 ++++- x/store/handler.go | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/x/association/service.go b/x/association/service.go index 3e81f8ca..d30e76c1 100644 --- a/x/association/service.go +++ b/x/association/service.go @@ -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 } } diff --git a/x/store/handler.go b/x/store/handler.go index 8f7a7a20..d5b0f65a 100644 --- a/x/store/handler.go +++ b/x/store/handler.go @@ -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 {