diff --git a/api/config/add.go b/api/config/add.go index 076375a5..37be3895 100644 --- a/api/config/add.go +++ b/api/config/add.go @@ -76,9 +76,7 @@ func AddConfig(c *gin.Context) { output := nginx.Reload() if nginx.GetLogLevel(output) >= nginx.Warn { - c.JSON(http.StatusInternalServerError, gin.H{ - "message": output, - }) + cosy.ErrHandler(c, cosy.WrapErrorWithParams(config.ErrNginxReloadFailed, output)) return } diff --git a/app/src/constants/errors/config.ts b/app/src/constants/errors/config.ts index e1c47eed..4794c6f2 100644 --- a/app/src/constants/errors/config.ts +++ b/app/src/constants/errors/config.ts @@ -1,4 +1,6 @@ export default { 50006: () => $gettext('Path: {0} is not under the nginx conf dir: {1}'), 50007: () => $gettext('Destination file: {0} already exists'), + 50008: () => $gettext('Nginx test failed: {0}'), + 50009: () => $gettext('Nginx reload failed: {0}'), } diff --git a/app/src/constants/errors/site.ts b/app/src/constants/errors/site.ts index 37a09dee..f82b3f37 100644 --- a/app/src/constants/errors/site.ts +++ b/app/src/constants/errors/site.ts @@ -3,4 +3,6 @@ export default { 50001: () => $gettext('Destination file already exists'), 50002: () => $gettext('Site is enabled'), 50003: () => $gettext('Site is in maintenance mode'), + 50004: () => $gettext('Nginx test failed: {0}'), + 50005: () => $gettext('Nginx reload failed: {0}'), } diff --git a/app/src/constants/errors/stream.ts b/app/src/constants/errors/stream.ts index 8c45d3e9..d3086d0d 100644 --- a/app/src/constants/errors/stream.ts +++ b/app/src/constants/errors/stream.ts @@ -2,4 +2,6 @@ export default { 40401: () => $gettext('Stream not found'), 50001: () => $gettext('Destination file already exists'), 50002: () => $gettext('Stream is enabled'), + 50003: () => $gettext('Nginx test failed: {0}'), + 50004: () => $gettext('Nginx reload failed: {0}'), } diff --git a/app/src/language/ar/app.po b/app/src/language/ar/app.po index f284d693..20009324 100644 --- a/app/src/language/ar/app.po +++ b/app/src/language/ar/app.po @@ -2689,6 +2689,12 @@ msgstr "مسار PID لـ Nginx" msgid "Nginx Reload Command" msgstr "أمر إعادة تحميل Nginx" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "فشل في التفعيل %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2714,6 +2720,12 @@ msgstr "تم إعادة تشغيل Nginx بنجاح" msgid "Nginx Test Config Command" msgstr "أمر إعادة تشغيل Nginx" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "فشل في التفعيل %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4728,7 +4740,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/de_DE/app.po b/app/src/language/de_DE/app.po index 51f310d7..14eb477a 100644 --- a/app/src/language/de_DE/app.po +++ b/app/src/language/de_DE/app.po @@ -2765,6 +2765,12 @@ msgstr "Nginx PID-Pfad" msgid "Nginx Reload Command" msgstr "Befehl zum Neuladen von Nginx" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Aktiviern von %{msg} fehlgeschlagen" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2792,6 +2798,12 @@ msgstr "Speichern erfolgreich" msgid "Nginx Test Config Command" msgstr "Beffehl zum Neustarten von Nginx" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Aktiviern von %{msg} fehlgeschlagen" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4873,7 +4885,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/en/app.po b/app/src/language/en/app.po index c361ac27..2b94df3d 100644 --- a/app/src/language/en/app.po +++ b/app/src/language/en/app.po @@ -2735,6 +2735,12 @@ msgstr "" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Failed to enable %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2761,6 +2767,12 @@ msgstr "Saved successfully" msgid "Nginx Test Config Command" msgstr "" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Failed to enable %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4780,7 +4792,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/es/app.po b/app/src/language/es/app.po index e58e2310..c343eab7 100644 --- a/app/src/language/es/app.po +++ b/app/src/language/es/app.po @@ -2694,6 +2694,12 @@ msgstr "Ruta de registro de errores de Nginx" msgid "Nginx Reload Command" msgstr "Comando de recarga de Nginx" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Error al habilitar %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2720,6 +2726,12 @@ msgstr "Nginx reiniciado con éxito" msgid "Nginx Test Config Command" msgstr "Comando de inicio de terminal" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Error al habilitar %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4774,7 +4786,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/fr_FR/app.po b/app/src/language/fr_FR/app.po index ee73c822..afdc5148 100644 --- a/app/src/language/fr_FR/app.po +++ b/app/src/language/fr_FR/app.po @@ -2780,6 +2780,12 @@ msgstr "Chemin du journal des erreurs Nginx" msgid "Nginx Reload Command" msgstr "Commande de démarrage du terminal" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Impossible d'activer %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2806,6 +2812,12 @@ msgstr "Nginx a redémarré avec succès" msgid "Nginx Test Config Command" msgstr "Commande de démarrage du terminal" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Impossible d'activer %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4838,7 +4850,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/ko_KR/app.po b/app/src/language/ko_KR/app.po index 07972166..e7757c15 100644 --- a/app/src/language/ko_KR/app.po +++ b/app/src/language/ko_KR/app.po @@ -2696,6 +2696,12 @@ msgstr "Nginx 오류 로그 경로" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "%{msg} 활성화 실패" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2724,6 +2730,12 @@ msgstr "Nginx가 성공적으로 재시작됨" msgid "Nginx Test Config Command" msgstr "터미널 시작 명령" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "%{msg} 활성화 실패" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4753,7 +4765,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/messages.pot b/app/src/language/messages.pot index eb577684..1369d99c 100644 --- a/app/src/language/messages.pot +++ b/app/src/language/messages.pot @@ -2500,6 +2500,12 @@ msgstr "" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 +#: src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +msgid "Nginx reload failed: {0}" +msgstr "" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2524,6 +2530,12 @@ msgstr "" msgid "Nginx Test Config Command" msgstr "" +#: src/constants/errors/config.ts:4 +#: src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +msgid "Nginx test failed: {0}" +msgstr "" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4312,7 +4324,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 +#: src/layouts/HeaderLayout.vue:49 #: src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" diff --git a/app/src/language/ru_RU/app.po b/app/src/language/ru_RU/app.po index 4dd97017..646b2cf7 100644 --- a/app/src/language/ru_RU/app.po +++ b/app/src/language/ru_RU/app.po @@ -2674,6 +2674,12 @@ msgstr "Путь для Nginx Error Log" msgid "Nginx Reload Command" msgstr "Команда перезагрузки Nginx" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Не удалось включить %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2700,6 +2706,12 @@ msgstr "Nginx успешно перезапущен" msgid "Nginx Test Config Command" msgstr "Терминальная команда запуска" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Не удалось включить %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4720,7 +4732,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/tr_TR/app.po b/app/src/language/tr_TR/app.po index 8d3aba9b..9e917c5c 100644 --- a/app/src/language/tr_TR/app.po +++ b/app/src/language/tr_TR/app.po @@ -2741,6 +2741,12 @@ msgstr "Nginx Hata Günlüğü Yolu" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Etkinleştirilemedi %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2769,6 +2775,12 @@ msgstr "Nginx başarıyla yeniden başlatıldı" msgid "Nginx Test Config Command" msgstr "Terminal Başlatma Komutu" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Etkinleştirilemedi %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4997,7 +5009,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/uk_UA/app.po b/app/src/language/uk_UA/app.po index d21c89e0..3fad9987 100644 --- a/app/src/language/uk_UA/app.po +++ b/app/src/language/uk_UA/app.po @@ -2516,6 +2516,11 @@ msgstr "" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +msgid "Nginx reload failed: {0}" +msgstr "" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2540,6 +2545,11 @@ msgstr "" msgid "Nginx Test Config Command" msgstr "" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +msgid "Nginx test failed: {0}" +msgstr "" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4413,7 +4423,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/vi_VN/app.po b/app/src/language/vi_VN/app.po index af334812..a81615fe 100644 --- a/app/src/language/vi_VN/app.po +++ b/app/src/language/vi_VN/app.po @@ -2730,6 +2730,12 @@ msgstr "Vị trí lưu log lỗi (Error log) của Nginx" msgid "Nginx Reload Command" msgstr "" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "Không thể bật %{msg}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "" @@ -2756,6 +2762,12 @@ msgstr "Restart Nginx thành công" msgid "Nginx Test Config Command" msgstr "" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "Không thể bật %{msg}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4776,7 +4788,7 @@ msgstr "" msgid "Workers" msgstr "" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "" diff --git a/app/src/language/zh_CN/app.po b/app/src/language/zh_CN/app.po index 4da5e155..e3e96162 100644 --- a/app/src/language/zh_CN/app.po +++ b/app/src/language/zh_CN/app.po @@ -3,7 +3,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2025-04-18 14:05+0800\n" +"PO-Revision-Date: 2025-04-18 16:49+0800\n" "Last-Translator: 0xJacky \n" "Language-Team: Chinese (Simplified Han script) \n" @@ -2526,6 +2526,11 @@ msgstr "Nginx PID 路径" msgid "Nginx Reload Command" msgstr "Nginx 重载命令" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +msgid "Nginx reload failed: {0}" +msgstr "Nginx 重载失败:{0}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "Nginx 重载操作已发送到远程节点" @@ -2550,6 +2555,11 @@ msgstr "Nginx 重启成功" msgid "Nginx Test Config Command" msgstr "Nginx 测试配置命令" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +msgid "Nginx test failed: {0}" +msgstr "Nginx 测试失败:{0}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "Nginx 理论最高性能" @@ -4458,7 +4468,7 @@ msgstr "工作进程" msgid "Workers" msgstr "Workers" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 msgid "Workspace" msgstr "工作区" diff --git a/app/src/language/zh_TW/app.po b/app/src/language/zh_TW/app.po index 1741ce47..66a4043c 100644 --- a/app/src/language/zh_TW/app.po +++ b/app/src/language/zh_TW/app.po @@ -2538,6 +2538,12 @@ msgstr "Nginx PID 路徑" msgid "Nginx Reload Command" msgstr "Nginx 重新載入指令" +#: src/constants/errors/config.ts:5 src/constants/errors/site.ts:7 +#: src/constants/errors/stream.ts:6 +#, fuzzy +msgid "Nginx reload failed: {0}" +msgstr "讀取檔案失敗:{0}" + #: src/views/environments/list/Environment.vue:41 msgid "Nginx reload operations have been dispatched to remote nodes" msgstr "Nginx 重新載入操作已分發至遠端節點" @@ -2562,6 +2568,12 @@ msgstr "Nginx 重啟成功" msgid "Nginx Test Config Command" msgstr "Nginx 測試設定指令" +#: src/constants/errors/config.ts:4 src/constants/errors/site.ts:6 +#: src/constants/errors/stream.ts:5 +#, fuzzy +msgid "Nginx test failed: {0}" +msgstr "無法建立檔案:{0}" + #: src/views/dashboard/components/PerformanceTablesCard.vue:180 msgid "Nginx theoretical maximum performance" msgstr "" @@ -4471,7 +4483,7 @@ msgstr "worker 行程" msgid "Workers" msgstr "worker" -#: src/layouts/HeaderLayout.vue:40 src/routes/index.ts:56 +#: src/layouts/HeaderLayout.vue:49 src/routes/index.ts:56 #: src/views/workspace/WorkSpace.vue:52 #, fuzzy msgid "Workspace" diff --git a/app/src/layouts/HeaderLayout.vue b/app/src/layouts/HeaderLayout.vue index 028a53ac..b287c99a 100644 --- a/app/src/layouts/HeaderLayout.vue +++ b/app/src/layouts/HeaderLayout.vue @@ -35,13 +35,6 @@ const isWorkspace = computed(() => {
-
- - - - - -
{ +
+ + + + + +
+ @@ -98,8 +99,6 @@ const isWorkspace = computed(() => { } .workspace-entry { - position: absolute; - left: 20px; @media (max-width: 600px) { display: none; } diff --git a/cmd/errdef/generate.go b/cmd/errdef/generate.go index d7ae192e..6fb7c31e 100644 --- a/cmd/errdef/generate.go +++ b/cmd/errdef/generate.go @@ -1,4 +1,4 @@ -//go:generate go run . -project . -type ts -output ../../app/src/constants/errors -ignore-dirs .devcontainer,app,.github +//go:generate go run . -project ../../ -type ts -output ../../app/src/constants/errors -ignore-dirs .devcontainer,app,.github,cmd package main import "github.com/uozi-tech/cosy/errdef" diff --git a/internal/config/errors.go b/internal/config/errors.go index 0e6d4482..b90c7c31 100644 --- a/internal/config/errors.go +++ b/internal/config/errors.go @@ -6,4 +6,6 @@ var ( e = cosy.NewErrorScope("config") ErrPathIsNotUnderTheNginxConfDir = e.New(50006, "path: {0} is not under the nginx conf dir: {1}") ErrDstFileExists = e.New(50007, "destination file: {0} already exists") + ErrNginxTestFailed = e.New(50008, "nginx test failed: {0}") + ErrNginxReloadFailed = e.New(50009, "nginx reload failed: {0}") ) diff --git a/internal/config/save.go b/internal/config/save.go index 72efc02d..25f7e98d 100644 --- a/internal/config/save.go +++ b/internal/config/save.go @@ -1,13 +1,13 @@ package config import ( - "fmt" "os" "github.com/0xJacky/Nginx-UI/internal/helper" "github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/query" + "github.com/uozi-tech/cosy" "gorm.io/gen/field" ) @@ -47,7 +47,7 @@ func Save(absPath string, content string, cfg *model.Config) (err error) { output := nginx.Reload() if nginx.GetLogLevel(output) >= nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } err = SyncToRemoteServer(cfg) diff --git a/internal/site/disable.go b/internal/site/disable.go index b75808fa..7a4f8205 100644 --- a/internal/site/disable.go +++ b/internal/site/disable.go @@ -2,15 +2,17 @@ package site import ( "fmt" - "github.com/0xJacky/Nginx-UI/internal/nginx" - "github.com/0xJacky/Nginx-UI/internal/notification" - "github.com/0xJacky/Nginx-UI/model" - "github.com/go-resty/resty/v2" - "github.com/uozi-tech/cosy/logger" "net/http" "os" "runtime" "sync" + + "github.com/0xJacky/Nginx-UI/internal/nginx" + "github.com/0xJacky/Nginx-UI/internal/notification" + "github.com/0xJacky/Nginx-UI/model" + "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" + "github.com/uozi-tech/cosy/logger" ) // Disable disables a site by removing the symlink in sites-enabled @@ -35,7 +37,7 @@ func Disable(name string) (err error) { output := nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } go syncDisable(name) diff --git a/internal/site/enable.go b/internal/site/enable.go index 5a27d9ac..4fba2057 100644 --- a/internal/site/enable.go +++ b/internal/site/enable.go @@ -11,6 +11,7 @@ import ( "github.com/0xJacky/Nginx-UI/internal/nginx" "github.com/0xJacky/Nginx-UI/internal/notification" "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy/logger" ) @@ -37,12 +38,12 @@ func Enable(name string) (err error) { output := nginx.TestConf() if nginx.GetLogLevel(output) > nginx.Warn { _ = os.Remove(enabledConfigFilePath) - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } go syncEnable(name) diff --git a/internal/site/errors.go b/internal/site/errors.go index 6d335fc9..74cd191e 100644 --- a/internal/site/errors.go +++ b/internal/site/errors.go @@ -8,4 +8,6 @@ var ( ErrDstFileExists = e.New(50001, "destination file already exists") ErrSiteIsEnabled = e.New(50002, "site is enabled") ErrSiteIsInMaintenance = e.New(50003, "site is in maintenance mode") + ErrNginxTestFailed = e.New(50004, "nginx test failed: {0}") + ErrNginxReloadFailed = e.New(50005, "nginx reload failed: {0}") ) diff --git a/internal/site/maintenance.go b/internal/site/maintenance.go index d93916c1..74a36dbf 100644 --- a/internal/site/maintenance.go +++ b/internal/site/maintenance.go @@ -16,6 +16,7 @@ import ( "github.com/go-resty/resty/v2" "github.com/tufanbarisyildirim/gonginx/config" "github.com/tufanbarisyildirim/gonginx/parser" + "github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy/logger" cSettings "github.com/uozi-tech/cosy/settings" ) @@ -82,13 +83,13 @@ func EnableMaintenance(name string) (err error) { if helper.FileExists(originalEnabledPath + "_backup") { _ = os.Rename(originalEnabledPath+"_backup", originalEnabledPath) } - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } // Reload nginx output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } // Synchronize with other nodes diff --git a/internal/site/save.go b/internal/site/save.go index 2210356d..1daf6a54 100644 --- a/internal/site/save.go +++ b/internal/site/save.go @@ -14,6 +14,7 @@ import ( "github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/query" "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy/logger" ) @@ -40,13 +41,13 @@ func Save(name string, content string, overwrite bool, envGroupId uint64, syncNo output := nginx.TestConf() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } if postAction == model.PostSyncActionReloadNginx { output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } } } diff --git a/internal/stream/disable.go b/internal/stream/disable.go index e6f5cc43..14ab4c61 100644 --- a/internal/stream/disable.go +++ b/internal/stream/disable.go @@ -2,15 +2,17 @@ package stream import ( "fmt" - "github.com/0xJacky/Nginx-UI/internal/nginx" - "github.com/0xJacky/Nginx-UI/internal/notification" - "github.com/0xJacky/Nginx-UI/model" - "github.com/go-resty/resty/v2" - "github.com/uozi-tech/cosy/logger" "net/http" "os" "runtime" "sync" + + "github.com/0xJacky/Nginx-UI/internal/nginx" + "github.com/0xJacky/Nginx-UI/internal/notification" + "github.com/0xJacky/Nginx-UI/model" + "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" + "github.com/uozi-tech/cosy/logger" ) // Disable disables a site by removing the symlink in sites-enabled @@ -35,7 +37,7 @@ func Disable(name string) (err error) { output := nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } go syncDisable(name) diff --git a/internal/stream/enable.go b/internal/stream/enable.go index e1839090..055a2b11 100644 --- a/internal/stream/enable.go +++ b/internal/stream/enable.go @@ -2,15 +2,17 @@ package stream import ( "fmt" - "github.com/0xJacky/Nginx-UI/internal/helper" - "github.com/0xJacky/Nginx-UI/internal/nginx" - "github.com/0xJacky/Nginx-UI/internal/notification" - "github.com/go-resty/resty/v2" - "github.com/uozi-tech/cosy/logger" "net/http" "os" "runtime" "sync" + + "github.com/0xJacky/Nginx-UI/internal/helper" + "github.com/0xJacky/Nginx-UI/internal/nginx" + "github.com/0xJacky/Nginx-UI/internal/notification" + "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" + "github.com/uozi-tech/cosy/logger" ) // Enable enables a site by creating a symlink in sites-enabled @@ -36,12 +38,12 @@ func Enable(name string) (err error) { output := nginx.TestConf() if nginx.GetLogLevel(output) > nginx.Warn { _ = os.Remove(enabledConfigFilePath) - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } go syncEnable(name) diff --git a/internal/stream/errors.go b/internal/stream/errors.go index 3bb02ec7..37c4c48d 100644 --- a/internal/stream/errors.go +++ b/internal/stream/errors.go @@ -7,4 +7,6 @@ var ( ErrStreamNotFound = e.New(40401, "stream not found") ErrDstFileExists = e.New(50001, "destination file already exists") ErrStreamIsEnabled = e.New(50002, "stream is enabled") + ErrNginxTestFailed = e.New(50003, "nginx test failed: {0}") + ErrNginxReloadFailed = e.New(50004, "nginx reload failed: {0}") ) diff --git a/internal/stream/rename.go b/internal/stream/rename.go index 2620a0b1..cf3b07d2 100644 --- a/internal/stream/rename.go +++ b/internal/stream/rename.go @@ -7,6 +7,7 @@ import ( "github.com/0xJacky/Nginx-UI/internal/notification" "github.com/0xJacky/Nginx-UI/query" "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy/logger" "net/http" "os" @@ -49,13 +50,13 @@ func Rename(oldName string, newName string) (err error) { // test nginx configuration output := nginx.TestConf() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } // reload nginx output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } go syncRename(oldName, newName) diff --git a/internal/stream/save.go b/internal/stream/save.go index 3b815594..b766ba98 100644 --- a/internal/stream/save.go +++ b/internal/stream/save.go @@ -14,6 +14,7 @@ import ( "github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/query" "github.com/go-resty/resty/v2" + "github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy/logger" ) @@ -40,13 +41,13 @@ func Save(name string, content string, overwrite bool, syncNodeIds []uint64, pos output := nginx.TestConf() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxTestFailed, output) } if postAction == model.PostSyncActionReloadNginx { output = nginx.Reload() if nginx.GetLogLevel(output) > nginx.Warn { - return fmt.Errorf("%s", output) + return cosy.WrapErrorWithParams(ErrNginxReloadFailed, output) } } }