check error returns

This commit is contained in:
Amolith 2023-09-24 17:08:00 -04:00
parent 9c3a304af8
commit d65a893962
Signed by: Amolith
GPG Key ID: 8AE30347CE28D101
1 changed files with 32 additions and 11 deletions

43
ws.go
View File

@ -39,22 +39,31 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
url := bmStrict.Sanitize(params.Get("url")) url := bmStrict.Sanitize(params.Get("url"))
if url == "" { if url == "" {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("No URL provided")) _, err := w.Write([]byte("No URL provided"))
if err != nil {
fmt.Println(err)
}
return return
} }
forge := bmStrict.Sanitize(params.Get("forge")) forge := bmStrict.Sanitize(params.Get("forge"))
if forge == "" { if forge == "" {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("No forge provided")) _, err := w.Write([]byte("No forge provided"))
if err != nil {
fmt.Println(err)
}
return return
} }
name := bmStrict.Sanitize(params.Get("name")) name := bmStrict.Sanitize(params.Get("name"))
if name == "" { if name == "" {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("No name provided")) _, err := w.Write([]byte("No name provided"))
return if err != nil {
fmt.Println(err)
}
} }
proj := project{ proj := project{
@ -65,8 +74,11 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
proj, err := getReleases(proj) proj, err := getReleases(proj)
if err != nil { if err != nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(fmt.Sprintf("Error getting releases: %s", err))) _, err := w.Write([]byte(fmt.Sprintf("Error getting releases: %s", err)))
return if err != nil {
fmt.Println(err)
}
} }
tmpl := template.Must(template.ParseFS(fs, "static/select-release.html")) tmpl := template.Must(template.ParseFS(fs, "static/select-release.html"))
if err := tmpl.Execute(w, proj); err != nil { if err := tmpl.Execute(w, proj); err != nil {
@ -76,8 +88,11 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
url := params.Get("url") url := params.Get("url")
if url == "" { if url == "" {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("No URL provided")) _, err := w.Write([]byte("No URL provided"))
return if err != nil {
fmt.Println(err)
}
} }
untrack(url) untrack(url)
@ -86,7 +101,10 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
} }
if r.Method == http.MethodPost { if r.Method == http.MethodPost {
r.ParseForm() err := r.ParseForm()
if err != nil {
fmt.Println(err)
}
nameValue := bmStrict.Sanitize(r.FormValue("name")) nameValue := bmStrict.Sanitize(r.FormValue("name"))
urlValue := bmStrict.Sanitize(r.FormValue("url")) urlValue := bmStrict.Sanitize(r.FormValue("url"))
forgeValue := bmStrict.Sanitize(r.FormValue("forge")) forgeValue := bmStrict.Sanitize(r.FormValue("forge"))
@ -105,8 +123,11 @@ func newHandler(w http.ResponseWriter, r *http.Request) {
if nameValue == "" && urlValue == "" && forgeValue == "" && releaseValue == "" { if nameValue == "" && urlValue == "" && forgeValue == "" && releaseValue == "" {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("No data provided")) _, err := w.Write([]byte("No data provided"))
return if err != nil {
fmt.Println(err)
}
} }
} }
} }