From fc401ffd8f256b3c1d4557791c096eb95a6089c4 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Mon, 30 Dec 2024 17:17:49 +0800 Subject: [PATCH] fix: Optimize image deletion error return (#7602) Refs #7068 --- backend/app/service/image.go | 3 +++ backend/constant/errs.go | 9 +++++---- backend/i18n/lang/en.yaml | 1 + backend/i18n/lang/ru.yaml | 1 + backend/i18n/lang/zh-Hant.yaml | 1 + backend/i18n/lang/zh.yaml | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/app/service/image.go b/backend/app/service/image.go index f860df59e..f40f8c923 100644 --- a/backend/app/service/image.go +++ b/backend/app/service/image.go @@ -439,6 +439,9 @@ func (u *ImageService) ImageRemove(req dto.BatchDelete) error { } return buserr.WithDetail(constant.ErrInUsed, id, nil) } + if strings.Contains(err.Error(), "image has dependent") { + return buserr.New(constant.ErrObjectBeDependent) + } return err } } diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 943d23037..066ef5e81 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -126,10 +126,11 @@ var ( // container var ( - ErrInUsed = "ErrInUsed" - ErrObjectInUsed = "ErrObjectInUsed" - ErrPortRules = "ErrPortRules" - ErrPgImagePull = "ErrPgImagePull" + ErrInUsed = "ErrInUsed" + ErrObjectInUsed = "ErrObjectInUsed" + ErrObjectBeDependent = "ErrObjectBeDependent" + ErrPortRules = "ErrPortRules" + ErrPgImagePull = "ErrPgImagePull" ) // runtime diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index 6034c2888..00e23e960 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -146,6 +146,7 @@ ErrTypeOfRedis: "The recovery file type does not match the current persistence m #container ErrInUsed: "{{ .detail }} is in use and can't be deleted" ErrObjectInUsed: "This object is in use and can't be deleted" +ErrObjectBeDependent: "This image is dependent on other images and can't be deleted" ErrPortRules: "The number of ports does not match, please re-enter!" ErrPgImagePull: "Image pull timeout. Please configure image acceleration or manually pull the postgres:16.0-alpine image and try again" diff --git a/backend/i18n/lang/ru.yaml b/backend/i18n/lang/ru.yaml index 7f5b2e0d7..8ee764b17 100644 --- a/backend/i18n/lang/ru.yaml +++ b/backend/i18n/lang/ru.yaml @@ -146,6 +146,7 @@ ErrTypeOfRedis: "Тип восстановленного файла не соо #container ErrInUsed: "{{ .detail }} используется и не может быть удален" ErrObjectInUsed: "Этот объект используется и не может быть удален" +ErrObjectBeDependent: "Этот образ зависит от других образов и не может быть удален" ErrPortRules: "Количество портов не совпадает, пожалуйста, введите заново!" ErrPgImagePull: "Тайм-аут загрузки образа. Пожалуйста, настройте ускорение загрузки образа или вручную загрузите образ postgres:16.0-alpine и попробуйте снова" diff --git a/backend/i18n/lang/zh-Hant.yaml b/backend/i18n/lang/zh-Hant.yaml index f34185838..77e1a0e2f 100644 --- a/backend/i18n/lang/zh-Hant.yaml +++ b/backend/i18n/lang/zh-Hant.yaml @@ -146,6 +146,7 @@ ErrTypeOfRedis: "恢復文件類型與目前持久化方式不匹配,請修改 #container ErrInUsed: "{{ .detail }} 正被使用,無法刪除" ErrObjectInUsed: "該對象正被使用,無法刪除" +ErrObjectBeDependent: "該鏡像依賴於其他鏡像,無法刪除" ErrPortRules: "埠數目不匹配,請重新輸入!" ErrPgImagePull: "鏡像拉取超時,請配置鏡像加速或手動拉取 postgres:16.0-alpine 鏡像後重試" diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 9b6d1e777..1711f3c16 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -146,6 +146,7 @@ ErrTypeOfRedis: "恢复文件类型与当前持久化方式不符,请修改后 #container ErrInUsed: "{{ .detail }} 正被使用,无法删除" ErrObjectInUsed: "该对象正被使用,无法删除" +ErrObjectBeDependent: "该镜像依赖于其他镜像,无法删除" ErrPortRules: "端口数目不匹配,请重新输入!" ErrPgImagePull: "镜像拉取超时,请配置镜像加速或手动拉取 postgres:16.0-alpine 镜像后重试"