MSP-7967 add error handling logic for try_lock

This commit is contained in:
Павел Комиссаров committed 2026-07-02 11:45:42 +03:00
1 parent 2a50f7d14f
commit 19b0d8f094
2 files changed
+37 -1

No files matched your search

+16 -1
View File
@@ -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
+21
View File
@@ -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": {