Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit a15f433

Browse files
author
Noah Hanjun Lee
authored
Display the message for setting auto unlock. (#179)
* Fix the status code of lock API * Display the message for setting auto-lock
1 parent 8729855 commit a15f433

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

internal/server/api/v1/repos/lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (r *Repo) UpdateLock(c *gin.Context) {
157157
l, err := r.i.FindLockByID(ctx, id)
158158
if ent.IsNotFound(err) {
159159
r.log.Warn("The lock is not found.", zap.Error(err))
160-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The lock is not found.")
160+
gb.ErrorResponse(c, http.StatusNotFound, "The lock is not found.")
161161
return
162162
} else if err != nil {
163163
r.log.Error("It has failed to find the lock.", zap.Error(err))
@@ -200,7 +200,7 @@ func (r *Repo) DeleteLock(c *gin.Context) {
200200
l, err := r.i.FindLockByID(ctx, id)
201201
if ent.IsNotFound(err) {
202202
r.log.Warn("The lock is not found.", zap.Error(err))
203-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The lock is not found.")
203+
gb.ErrorResponse(c, http.StatusNotFound, "The lock is not found.")
204204
return
205205
} else if err != nil {
206206
r.log.Error("It has failed to find the lock.", zap.Error(err))

ui/src/apis/lock.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StatusCodes } from "http-status-codes"
33
import { instance, headers } from "./setting"
44
import { _fetch } from "./_base"
55
import { UserData, mapDataToUser } from "./user"
6-
import { Lock, User, HttpForbiddenError, HttpUnprocessableEntityError } from "../models"
6+
import { Lock, User, HttpForbiddenError, HttpNotFoundError, HttpUnprocessableEntityError } from "../models"
77

88
interface LockData {
99
id: number
@@ -94,6 +94,11 @@ export const updateLock = async (namespace: string, name: string, id: number, pa
9494
throw new HttpForbiddenError(message)
9595
}
9696

97+
if (res.status === StatusCodes.NOT_FOUND) {
98+
const {message} = await res.json()
99+
throw new HttpNotFoundError(message)
100+
}
101+
97102
const lock = res.json()
98103
.then(data => mapDataToLock(data))
99104
return lock

ui/src/redux/repoLock.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { message } from "antd"
44
import {
55
Config,
66
Lock,
7-
HttpForbiddenError
7+
HttpForbiddenError,
8+
HttpNotFoundError
89
} from "../models"
910
import {
1011
getConfig,
@@ -107,11 +108,18 @@ export const setAutoUnlock = createAsyncThunk<Lock, {env: string, expiredAt: Dat
107108
}
108109

109110
try {
110-
return await updateLock(namespace, name, lock.id, {expiredAt})
111+
const ret = await updateLock(namespace, name, lock.id, {expiredAt})
112+
message.info(`Setting auto-unlock.`)
113+
114+
return ret
111115
} catch (e) {
112116
if (e instanceof HttpForbiddenError) {
113117
message.warn("Only write permission can enable auto unlock.", 3)
114118
}
119+
120+
if (e instanceof HttpNotFoundError) {
121+
message.warn("Lock is not found.")
122+
}
115123
return rejectWithValue(e)
116124
}
117125
},

0 commit comments

Comments
 (0)