From c6930ef57b56f35bc620ae05f9b8a5e57f9d5b7d Mon Sep 17 00:00:00 2001 From: Martin Charles Date: Mon, 2 Jun 2014 12:44:27 -0400 Subject: [PATCH] Fixed an Unhandled Error in badges.go There was an unhandled error in badges.go. If you pass an invalid branch to the badge handler (http://beta.drone.io/github.com/drone/drone/ status.svg?branch=this) the browser is told to redirect to a blank string. This is unintended behavior. Now, a 404 response is sent instead. --- pkg/handler/badges.go | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/pkg/handler/badges.go b/pkg/handler/badges.go index 3a98a3fcf..1994d6e5a 100644 --- a/pkg/handler/badges.go +++ b/pkg/handler/badges.go @@ -43,26 +43,29 @@ func Badge(w http.ResponseWriter, r *http.Request) error { // get the latest commit from the database // for the requested branch commit, err := database.GetBranch(repo.ID, branchParam) - if err == nil { - switch { - case commit.Status == "Success" && len(successParam) == 0: - // if no success image is provided, we serve a - // badge using the shields.io service - badge = badgeSuccess - case commit.Status == "Success" && len(successParam) != 0: - // otherwise we serve the user defined success badge - badge = successParam - case commit.Status == "Failure" && len(failureParam) == 0: - // if no failure image is provided, we serve a - // badge using the shields.io service - badge = badgeFailure - case commit.Status == "Failure" && len(failureParam) != 0: - // otherwise we serve the user defined failure badge - badge = failureParam - default: - // otherwise load unknown image - badge = badgeUnknown - } + if err != nil { + http.NotFound(w, r) + return nil + } + + switch { + case commit.Status == "Success" && len(successParam) == 0: + // if no success image is provided, we serve a + // badge using the shields.io service + badge = badgeSuccess + case commit.Status == "Success" && len(successParam) != 0: + // otherwise we serve the user defined success badge + badge = successParam + case commit.Status == "Failure" && len(failureParam) == 0: + // if no failure image is provided, we serve a + // badge using the shields.io service + badge = badgeFailure + case commit.Status == "Failure" && len(failureParam) != 0: + // otherwise we serve the user defined failure badge + badge = failureParam + default: + // otherwise load unknown image + badge = badgeUnknown } http.Redirect(w, r, badge, http.StatusSeeOther)