From 78517f80bbf797e21112a87e90c3286d9224d8bf Mon Sep 17 00:00:00 2001
From: wxiaoguang <wxiaoguang@gmail.com>
Date: Mon, 29 Apr 2024 08:23:35 +0800
Subject: [PATCH] Fix nil dereference on error (#30740) (#30746)

Backport #30740 manually

Co-authored-by: Chongyi Zheng <git@zcy.dev>
(cherry picked from commit d07019f539c475466748fbf730d7f270a92fdb8b)
---
 routers/api/actions/artifacts.go | 7 ++++---
 routers/web/repo/actions/view.go | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go
index 2f8b3d0210..4306df5cd8 100644
--- a/routers/api/actions/artifacts.go
+++ b/routers/api/actions/artifacts.go
@@ -467,14 +467,15 @@ func (ar artifactRoutes) downloadArtifact(ctx *ArtifactContext) {
 		log.Error("Error getting artifact: %v", err)
 		ctx.Error(http.StatusInternalServerError, err.Error())
 		return
-	} else if !exist {
+	}
+	if !exist {
 		log.Error("artifact with ID %d does not exist", artifactID)
 		ctx.Error(http.StatusNotFound, fmt.Sprintf("artifact with ID %d does not exist", artifactID))
 		return
 	}
 	if artifact.RunID != runID {
-		log.Error("Error dismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
-		ctx.Error(http.StatusBadRequest, err.Error())
+		log.Error("Error mismatch runID and artifactID, task: %v, artifact: %v", runID, artifactID)
+		ctx.Error(http.StatusBadRequest)
 		return
 	}
 
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index fa687bbb93..6176ac1278 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -552,7 +552,7 @@ func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions
 		return nil, nil
 	}
 	if len(jobs) == 0 {
-		ctx.Error(http.StatusNotFound, err.Error())
+		ctx.Error(http.StatusNotFound)
 		return nil, nil
 	}