Migrated URL validation out of database saving

This commit is contained in:
2018-11-17 17:07:33 +00:00
committed by cdramey
parent 5c669c8b93
commit 9f13f8e09b
3 changed files with 23 additions and 18 deletions

View File

@ -54,15 +54,20 @@ func (ctx *SubmitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Created: time.Now(),
}
err := ctx.Storage.AddQURL(q)
err := q.CheckValid()
if err != nil {
http.Error(w, fmt.Sprintf("Database error: %s", err.Error()),
http.StatusInternalServerError)
return
}
pg.Message = err.Error()
} else {
err := ctx.Storage.AddQURL(q)
if err != nil {
http.Error(w, fmt.Sprintf("Database error: %s", err.Error()),
http.StatusInternalServerError)
return
}
pg.Message = "URL Added."
pg.URL = fmt.Sprintf("https://qurl.org/%s", qurl.ToString(q.ID))
pg.Message = "URL Added."
pg.URL = fmt.Sprintf("https://qurl.org/%s", qurl.ToString(q.ID))
}
}
}