summary refs log tree commit diff stats
path: root/post.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-21 22:32:49 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-21 22:32:49 -0400
commit54a4f6f720979dc8c8d6224acd24f04d147ef761 (patch)
tree5c7d8c19d8ca0f145cee9234578e881366989b35 /post.go
parent360f7e248a065a766890db9b4f65757dc6365eb2 (diff)
downloadgetwtxt-54a4f6f720979dc8c8d6224acd24f04d147ef761.tar.gz
fixed http 400 response and test
Diffstat (limited to 'post.go')
-rw-r--r--post.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/post.go b/post.go
index b9c830e..25d1902 100644
--- a/post.go
+++ b/post.go
@@ -14,15 +14,13 @@ import (
 // registry before adding each user to the local cache.
 func apiPostUser(w http.ResponseWriter, r *http.Request) {
 	if err := r.ParseForm(); err != nil {
-		_, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err)))
-		log400(r, err)
+		log400(w, r, err)
 		return
 	}
 	nick := r.FormValue("nickname")
 	urls := r.FormValue("url")
 	if nick == "" || urls == "" {
-		_, _ = w.Write([]byte("400 Bad Request: Nickname or URL Missing\n"))
-		log400(r, fmt.Errorf("nickname or URL missing"))
+		log400(w, r, fmt.Errorf("Nickname or URL missing"))
 		return
 	}
 
@@ -30,8 +28,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	out, remoteRegistry, err := registry.GetTwtxt(urls)
 	if err != nil {
-		_, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err)))
-		log400(r, err)
+		log400(w, r, err)
 		return
 	}
 
@@ -42,8 +39,7 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 		err := twtxtCache.ScrapeRemoteRegistry(urls)
 		if err != nil {
-			_, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err)))
-			log400(r, err)
+			log400(w, r, err)
 			return
 		}
 		log200(r)
@@ -52,15 +48,13 @@ func apiPostUser(w http.ResponseWriter, r *http.Request) {
 
 	statuses, err := registry.ParseUserTwtxt(out, nick, urls)
 	if err != nil {
-		_, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err)))
-		log400(r, err)
+		log400(w, r, err)
 		return
 	}
 
 	err = twtxtCache.AddUser(nick, urls, uip, statuses)
 	if err != nil {
-		_, _ = w.Write([]byte(fmt.Sprintf("400 Bad Request: %v\n", err)))
-		log400(r, err)
+		log400(w, r, err)
 		return
 	}