From addf8cbe484ff971232dca96f1497f61ce6ebfea Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 22 Oct 2021 21:48:53 +0900 Subject: [PATCH 1/3] Fix the status code of lock API --- internal/server/api/v1/repos/lock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/server/api/v1/repos/lock.go b/internal/server/api/v1/repos/lock.go index 607e9b74..c039f748 100644 --- a/internal/server/api/v1/repos/lock.go +++ b/internal/server/api/v1/repos/lock.go @@ -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)) @@ -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)) From ede6bf9132890fe3f675c8f70ea3048ad59afb86 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 22 Oct 2021 21:49:25 +0900 Subject: [PATCH 2/3] Display the message for setting auto-lock --- ui/src/apis/lock.ts | 7 ++++++- ui/src/redux/repoLock.ts | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ui/src/apis/lock.ts b/ui/src/apis/lock.ts index f6585482..8fa279f9 100644 --- a/ui/src/apis/lock.ts +++ b/ui/src/apis/lock.ts @@ -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 @@ -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 diff --git a/ui/src/redux/repoLock.ts b/ui/src/redux/repoLock.ts index 39fcc26b..cd2ec7d6 100644 --- a/ui/src/redux/repoLock.ts +++ b/ui/src/redux/repoLock.ts @@ -1,10 +1,12 @@ import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit' import { message } from "antd" +import moment from 'moment' import { Config, Lock, - HttpForbiddenError + HttpForbiddenError, + HttpNotFoundError } from "../models" import { getConfig, @@ -107,11 +109,18 @@ export const setAutoUnlock = createAsyncThunk Date: Fri, 22 Oct 2021 21:49:50 +0900 Subject: [PATCH 3/3] Fix lint --- ui/src/redux/repoLock.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/src/redux/repoLock.ts b/ui/src/redux/repoLock.ts index cd2ec7d6..3dfc1a2d 100644 --- a/ui/src/redux/repoLock.ts +++ b/ui/src/redux/repoLock.ts @@ -1,6 +1,5 @@ import { createSlice, PayloadAction, createAsyncThunk } from '@reduxjs/toolkit' import { message } from "antd" -import moment from 'moment' import { Config,