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.
This commit is contained in:
Martin Charles 2014-06-02 12:44:27 -04:00
parent 0d25dc1595
commit c6930ef57b

View file

@ -43,26 +43,29 @@ func Badge(w http.ResponseWriter, r *http.Request) error {
// get the latest commit from the database // get the latest commit from the database
// for the requested branch // for the requested branch
commit, err := database.GetBranch(repo.ID, branchParam) commit, err := database.GetBranch(repo.ID, branchParam)
if err == nil { if err != nil {
switch { http.NotFound(w, r)
case commit.Status == "Success" && len(successParam) == 0: return nil
// if no success image is provided, we serve a }
// badge using the shields.io service
badge = badgeSuccess switch {
case commit.Status == "Success" && len(successParam) != 0: case commit.Status == "Success" && len(successParam) == 0:
// otherwise we serve the user defined success badge // if no success image is provided, we serve a
badge = successParam // badge using the shields.io service
case commit.Status == "Failure" && len(failureParam) == 0: badge = badgeSuccess
// if no failure image is provided, we serve a case commit.Status == "Success" && len(successParam) != 0:
// badge using the shields.io service // otherwise we serve the user defined success badge
badge = badgeFailure badge = successParam
case commit.Status == "Failure" && len(failureParam) != 0: case commit.Status == "Failure" && len(failureParam) == 0:
// otherwise we serve the user defined failure badge // if no failure image is provided, we serve a
badge = failureParam // badge using the shields.io service
default: badge = badgeFailure
// otherwise load unknown image case commit.Status == "Failure" && len(failureParam) != 0:
badge = badgeUnknown // otherwise we serve the user defined failure badge
} badge = failureParam
default:
// otherwise load unknown image
badge = badgeUnknown
} }
http.Redirect(w, r, badge, http.StatusSeeOther) http.Redirect(w, r, badge, http.StatusSeeOther)