From 19b0d8f09471c5f07fc512162aadd579ba775be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9A=D0=BE=D0=BC=D0=B8?= =?UTF-8?q?=D1=81=D1=81=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 2 Jul 2026 11:19:59 +0300 Subject: [PATCH] MSP-7967 add error handling logic for try_lock --- controller/locker.go | 17 ++++++++++++++++- docs/swagger.json | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/controller/locker.go b/controller/locker.go index c2ed792..ff56bd7 100644 --- a/controller/locker.go +++ b/controller/locker.go @@ -2,9 +2,13 @@ package controller import ( "context" + "errors" + "net/http" "isp-lock-service/domain" + "github.com/go-redsync/redsync/v4" + "github.com/txix-open/isp-kit/grpc/apierrors" "github.com/txix-open/isp-kit/log" ) @@ -49,9 +53,20 @@ func (l Locker) Lock(ctx context.Context, req domain.LockRequest) (*domain.LockR // @Accept json // @Produce json // @Success 200 {object} domain.LockResponse +// @Failure 423 {object} apierrors.Error // @Router /api/isp-lock-service/try_lock [POST] func (l Locker) TryLock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error) { - return l.s.TryLock(ctx, req) + var errTaken *redsync.ErrTaken + + resp, err := l.s.TryLock(ctx, req) + switch { + case errors.As(err, &errTaken): + return nil, apierrors.NewBusinessError(http.StatusLocked, err.Error(), err) + case err != nil: + return nil, err + } + + return resp, nil } // UnLock diff --git a/docs/swagger.json b/docs/swagger.json index 722860e..99df361 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -86,6 +86,12 @@ "schema": { "$ref": "#/definitions/domain.LockResponse" } + }, + "423": { + "description": "Locked", + "schema": { + "$ref": "#/definitions/apierrors.Error" + } } } } @@ -127,6 +133,21 @@ } }, "definitions": { + "apierrors.Error": { + "type": "object", + "properties": { + "details": { + "type": "object", + "additionalProperties": {} + }, + "errorCode": { + "type": "integer" + }, + "errorMessage": { + "type": "string" + } + } + }, "domain.LockResponse": { "type": "object", "properties": {