From 7e3bf2202c5b73670f3d1911281b730fb91b3873 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 17 Mar 2023 02:10:51 +0100 Subject: [PATCH] Return 404 if pipeline not exist and handle 404 errors in WebUI (#1627) --- server/api/pipeline.go | 6 +++++- web/src/App.vue | 4 ++++ web/src/assets/locales/en.json | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/api/pipeline.go b/server/api/pipeline.go index af01f8b60..022852515 100644 --- a/server/api/pipeline.go +++ b/server/api/pipeline.go @@ -101,7 +101,7 @@ func GetPipelines(c *gin.Context) { c.AbortWithStatus(http.StatusNotFound) return } - c.AbortWithStatus(http.StatusInternalServerError) + _ = c.AbortWithError(http.StatusInternalServerError, err) return } c.JSON(http.StatusOK, pipelines) @@ -123,6 +123,10 @@ func GetPipeline(c *gin.Context) { pl, err := _store.GetPipelineNumber(repo, num) if err != nil { + if errors.Is(err, types.RecordNotExist) { + c.AbortWithStatus(http.StatusNotFound) + return + } _ = c.AbortWithError(http.StatusInternalServerError, err) return } diff --git a/web/src/App.vue b/web/src/App.vue index 5725b561b..bd81ec59c 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -33,6 +33,10 @@ const i18n = useI18n(); // eslint-disable-next-line promise/prefer-await-to-callbacks apiClient.setErrorHandler((err) => { + if (err.status === 404) { + notify({ title: i18n.t('errors.not_found'), type: 'error' }); + return; + } notify({ title: err.message || i18n.t('unknown_error'), type: 'error' }); }); diff --git a/web/src/assets/locales/en.json b/web/src/assets/locales/en.json index 6dee01cb3..2422a64f0 100644 --- a/web/src/assets/locales/en.json +++ b/web/src/assets/locales/en.json @@ -20,6 +20,9 @@ "not_found": "Whoa 404, either we broke something or you had a typing mishap :-/", "back_home": "Back to home" }, + "errors": { + "not_found": "Server could not find requested object" + }, "time": { "tmpl": "MMM D, YYYY, HH:mm z", "weeks_short": "w",