Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/server/api/v1/repos/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *Repo) UpdateLock(c *gin.Context) {
l, err := r.i.FindLockByID(ctx, id)
if ent.IsNotFound(err) {
r.log.Warn("The lock is not found.", zap.Error(err))
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The lock is not found.")
gb.ErrorResponse(c, http.StatusNotFound, "The lock is not found.")
return
} else if err != nil {
r.log.Error("It has failed to find the lock.", zap.Error(err))
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *Repo) DeleteLock(c *gin.Context) {
l, err := r.i.FindLockByID(ctx, id)
if ent.IsNotFound(err) {
r.log.Warn("The lock is not found.", zap.Error(err))
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The lock is not found.")
gb.ErrorResponse(c, http.StatusNotFound, "The lock is not found.")
return
} else if err != nil {
r.log.Error("It has failed to find the lock.", zap.Error(err))
Expand Down
7 changes: 6 additions & 1 deletion ui/src/apis/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StatusCodes } from "http-status-codes"
import { instance, headers } from "./setting"
import { _fetch } from "./_base"
import { UserData, mapDataToUser } from "./user"
import { Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models"
import { Lock, User, HttpForbiddenError, HttpNotFoundError, HttpUnprocessableEntityError } from "../models"

interface LockData {
id: number
Expand Down Expand Up @@ -94,6 +94,11 @@ export const updateLock = async (namespace: string, name: string, id: number, pa
throw new HttpForbiddenError(message)
}

if (res.status === StatusCodes.NOT_FOUND) {
const {message} = await res.json()
throw new HttpNotFoundError(message)
}

const lock = res.json()
.then(data => mapDataToLock(data))
return lock
Expand Down
12 changes: 10 additions & 2 deletions ui/src/redux/repoLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { message } from "antd"
import {
Config,
Lock,
HttpForbiddenError
HttpForbiddenError,
HttpNotFoundError
} from "../models"
import {
getConfig,
Expand Down Expand Up @@ -107,11 +108,18 @@ export const setAutoUnlock = createAsyncThunk<Lock, {env: string, expiredAt: Dat
}

try {
return await updateLock(namespace, name, lock.id, {expiredAt})
const ret = await updateLock(namespace, name, lock.id, {expiredAt})
message.info(`Setting auto-unlock.`)

return ret
} catch (e) {
if (e instanceof HttpForbiddenError) {
message.warn("Only write permission can enable auto unlock.", 3)
}

if (e instanceof HttpNotFoundError) {
message.warn("Lock is not found.")
}
return rejectWithValue(e)
}
},
Expand Down