Problem: http status codes use integer constants
Solution: replace http status codes with symbolic constants
This commit is contained in:
parent
9c8cec2c5b
commit
fd3a246f0d
|
@ -292,7 +292,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), 400)
|
http.Error(w, fmt.Sprintf("Bad Request: %s", err.Error()), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,10 +317,10 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else if r.URL.Path == "/session/callback" {
|
} else if r.URL.Path == "/session/callback" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
http.Error(w, "could not read cookie", 500)
|
http.Error(w, "could not read cookie", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,9 +342,9 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
saveSession(sessionVar, &sess, conn)
|
saveSession(sessionVar, &sess, conn)
|
||||||
log.Printf("SESSION: %#v\n", sess)
|
log.Printf("SESSION: %#v\n", sess)
|
||||||
if sess.NextURI != "" {
|
if sess.NextURI != "" {
|
||||||
http.Redirect(w, r, sess.NextURI, 302)
|
http.Redirect(w, r, sess.NextURI, http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else if r.URL.Path == "/settings/channel" {
|
} else if r.URL.Path == "/settings/channel" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionVar := c.Value
|
sessionVar := c.Value
|
||||||
|
@ -423,7 +423,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else if r.URL.Path == "/logs" {
|
} else if r.URL.Path == "/logs" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionVar := c.Value
|
sessionVar := c.Value
|
||||||
|
@ -451,7 +451,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else if r.URL.Path == "/settings" {
|
} else if r.URL.Path == "/settings" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sessionVar := c.Value
|
sessionVar := c.Value
|
||||||
|
@ -499,7 +499,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if !isLoggedIn(h.Backend, &sess) {
|
if !isLoggedIn(h.Backend, &sess) {
|
||||||
sess.NextURI = r.URL.String()
|
sess.NextURI = r.URL.String()
|
||||||
saveSession(sessionVar, &sess, conn)
|
saveSession(sessionVar, &sess, conn)
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +563,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.URL.Path == "/session" {
|
if r.URL.Path == "/session" {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,7 +574,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
endpoints, err := getEndpoints(me)
|
endpoints, err := getEndpoints(me)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Bad Request: %s, %s", err.Error(), me), 400)
|
http.Error(w, fmt.Sprintf("Bad Request: %s, %s", err.Error(), me), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -584,7 +584,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
sess, err := loadSession(sessionVar, conn)
|
sess, err := loadSession(sessionVar, conn)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,12 +596,12 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err = saveSession(sessionVar, &sess, conn)
|
err = saveSession(sessionVar, &sess, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authenticationURL := indieauth.CreateAuthenticationURL(*endpoints.AuthorizationEndpoint, endpoints.Me.String(), h.BaseURL, redirectURI, state)
|
authenticationURL := indieauth.CreateAuthenticationURL(*endpoints.AuthorizationEndpoint, endpoints.Me.String(), h.BaseURL, redirectURI, state)
|
||||||
http.Redirect(w, r, authenticationURL, 302)
|
http.Redirect(w, r, authenticationURL, http.StatusFound)
|
||||||
|
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/session/logout" {
|
} else if r.URL.Path == "/session/logout" {
|
||||||
|
@ -654,7 +654,7 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
redirectURI.RawQuery = q.Encode()
|
redirectURI.RawQuery = q.Encode()
|
||||||
|
|
||||||
log.Println(redirectURI)
|
log.Println(redirectURI)
|
||||||
http.Redirect(w, r, redirectURI.String(), 302)
|
http.Redirect(w, r, redirectURI.String(), http.StatusFound)
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/auth/token" {
|
} else if r.URL.Path == "/auth/token" {
|
||||||
grantType := r.FormValue("grant_type")
|
grantType := r.FormValue("grant_type")
|
||||||
|
@ -726,11 +726,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// }
|
// }
|
||||||
// h.Backend.Settings[uid] = setting
|
// h.Backend.Settings[uid] = setting
|
||||||
|
|
||||||
http.Redirect(w, r, "/settings", 302)
|
http.Redirect(w, r, "/settings", http.StatusFound)
|
||||||
return
|
return
|
||||||
} else if r.URL.Path == "/refresh" {
|
} else if r.URL.Path == "/refresh" {
|
||||||
h.Backend.RefreshFeeds()
|
h.Backend.RefreshFeeds()
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -741,14 +741,14 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
func httpSessionLogout(r *http.Request, w http.ResponseWriter, conn redis.Conn) {
|
func httpSessionLogout(r *http.Request, w http.ResponseWriter, conn redis.Conn) {
|
||||||
c, err := r.Cookie("session")
|
c, err := r.Cookie("session")
|
||||||
if err == http.ErrNoCookie {
|
if err == http.ErrNoCookie {
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sessionVar := c.Value
|
sessionVar := c.Value
|
||||||
_, _ = conn.Do("DEL", "session:"+sessionVar)
|
_, _ = conn.Do("DEL", "session:"+sessionVar)
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, "/", 302)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
type parsedEndpoints struct {
|
type parsedEndpoints struct {
|
||||||
|
|
|
@ -51,13 +51,13 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
leaseSeconds, err := strconv.ParseInt(leaseStr, 10, 64)
|
leaseSeconds, err := strconv.ParseInt(leaseStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error in hub.lease_seconds format %q: %s", leaseSeconds, err)
|
log.Printf("error in hub.lease_seconds format %q: %s", leaseSeconds, err)
|
||||||
http.Error(w, fmt.Sprintf("error in hub.lease_seconds format %q: %s", leaseSeconds, err), 400)
|
http.Error(w, fmt.Sprintf("error in hub.lease_seconds format %q: %s", leaseSeconds, err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = h.Backend.FeedSetLeaseSeconds(feed, leaseSeconds)
|
err = h.Backend.FeedSetLeaseSeconds(feed, leaseSeconds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error in while setting hub.lease_seconds: %s", err)
|
log.Printf("error in while setting hub.lease_seconds: %s", err)
|
||||||
http.Error(w, fmt.Sprintf("error in while setting hub.lease_seconds: %s", err), 400)
|
http.Error(w, fmt.Sprintf("error in while setting hub.lease_seconds: %s", err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
secret := h.Backend.GetSecret(feed)
|
secret := h.Backend.GetSecret(feed)
|
||||||
if secret == "" {
|
if secret == "" {
|
||||||
log.Printf("missing secret for feed %d\n", feed)
|
log.Printf("missing secret for feed %d\n", feed)
|
||||||
http.Error(w, "Unknown", 400)
|
http.Error(w, "Unknown", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if sig != "" {
|
if sig != "" {
|
||||||
if err := websub.ValidateHubSignature(sig, feedContent, []byte(secret)); err != nil {
|
if err := websub.ValidateHubSignature(sig, feedContent, []byte(secret)); err != nil {
|
||||||
log.Printf("could not validate signature: %+v", err)
|
log.Printf("could not validate signature: %+v", err)
|
||||||
http.Error(w, fmt.Sprintf("could not validate signature: %s", err), 400)
|
http.Error(w, fmt.Sprintf("could not validate signature: %s", err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func (h *incomingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
ct := r.Header.Get("Content-Type")
|
ct := r.Header.Get("Content-Type")
|
||||||
err = h.Backend.UpdateFeed(h.Processor, feed, ct, bytes.NewBuffer(feedContent))
|
err = h.Backend.UpdateFeed(h.Processor, feed, ct, bytes.NewBuffer(feedContent))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), 400)
|
http.Error(w, fmt.Sprintf("could not update feed: %s (%s)", ct, err), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,13 +86,13 @@ func WithAuth(handler http.Handler, b *memoryBackend) http.Handler {
|
||||||
}
|
}
|
||||||
if !authorized {
|
if !authorized {
|
||||||
log.Printf("Token could not be validated")
|
log.Printf("Token could not be validated")
|
||||||
http.Error(w, "Can't validate token", 403)
|
http.Error(w, "Can't validate token", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if token.Me != b.Me { // FIXME: Me should be part of the request
|
if token.Me != b.Me { // FIXME: Me should be part of the request
|
||||||
log.Printf("Missing \"me\" in token response: %#v\n", token)
|
log.Printf("Missing \"me\" in token response: %#v\n", token)
|
||||||
http.Error(w, "Wrong me", 403)
|
http.Error(w, "Wrong me", http.StatusForbidden)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "bad request", 400)
|
http.Error(w, "bad request", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,13 +50,13 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
channel, err = getChannelFromAuthorization(r, conn)
|
channel, err = getChannelFromAuthorization(r, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, "unauthorized", 401)
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// no channel is found
|
// no channel is found
|
||||||
if channel == "" {
|
if channel == "" {
|
||||||
http.Error(w, "bad request, unknown channel", 400)
|
http.Error(w, "bad request, unknown channel", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
item, err := parseIncomingItem(r)
|
item, err := parseIncomingItem(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 400)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Printf("Item published: %s", item.Published)
|
log.Printf("Item published: %s", item.Published)
|
||||||
|
@ -76,7 +76,7 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
newID, err := generateItemID(conn, channel)
|
newID, err := generateItemID(conn, channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.ID = newID
|
item.ID = newID
|
||||||
|
@ -95,13 +95,13 @@ func (h *micropubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err = json.NewEncoder(w).Encode(map[string]string{"ok": "1"}); err != nil {
|
if err = json.NewEncoder(w).Encode(map[string]string{"ok": "1"}); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, "internal server error", 500)
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Error(w, "Method not allowed", 405)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateItemID(conn redis.Conn, channel string) (string, error) {
|
func generateItemID(conn redis.Conn, channel string) (string, error) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ func respondJSON(w http.ResponseWriter, value interface{}) {
|
||||||
w.Header().Add("Content-Type", OutputContentType)
|
w.Header().Add("Content-Type", OutputContentType)
|
||||||
err := jw.Encode(value)
|
err := jw.Encode(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
channels, err := h.backend.ChannelsGetList()
|
channels, err := h.backend.ChannelsGetList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, map[string][]microsub.Channel{
|
respondJSON(w, map[string][]microsub.Channel{
|
||||||
|
@ -80,7 +80,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
timeline, err := h.backend.TimelineGet(values.Get("before"), values.Get("after"), values.Get("channel"))
|
timeline, err := h.backend.TimelineGet(values.Get("before"), values.Get("after"), values.Get("channel"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, timeline)
|
respondJSON(w, timeline)
|
||||||
|
@ -88,7 +88,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
timeline, err := h.backend.PreviewURL(values.Get("url"))
|
timeline, err := h.backend.PreviewURL(values.Get("url"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, timeline)
|
respondJSON(w, timeline)
|
||||||
|
@ -97,7 +97,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
following, err := h.backend.FollowGetList(channel)
|
following, err := h.backend.FollowGetList(channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, map[string][]microsub.Feed{
|
respondJSON(w, map[string][]microsub.Feed{
|
||||||
|
@ -107,7 +107,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
events, err := h.backend.Events()
|
events, err := h.backend.Events()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, "could not start sse connection", 500)
|
http.Error(w, "could not start sse connection", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove this client from the map of connected clients
|
// Remove this client from the map of connected clients
|
||||||
|
@ -127,10 +127,10 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
err = sse.WriteMessages(w, events)
|
err = sse.WriteMessages(w, events)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, "internal server error", 500)
|
http.Error(w, "internal server error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, fmt.Sprintf("unknown action %s", action), 400)
|
http.Error(w, fmt.Sprintf("unknown action %s", action), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -147,7 +147,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
err := h.backend.ChannelsDelete(uid)
|
err := h.backend.ChannelsDelete(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, []string{})
|
respondJSON(w, []string{})
|
||||||
|
@ -158,7 +158,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
channel, err := h.backend.ChannelsCreate(name)
|
channel, err := h.backend.ChannelsCreate(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, channel)
|
respondJSON(w, channel)
|
||||||
|
@ -166,7 +166,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
channel, err := h.backend.ChannelsUpdate(uid, name)
|
channel, err := h.backend.ChannelsUpdate(uid, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, channel)
|
respondJSON(w, channel)
|
||||||
|
@ -177,7 +177,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// h.HubIncomingBackend.CreateFeed(url, uid)
|
// h.HubIncomingBackend.CreateFeed(url, uid)
|
||||||
feed, err := h.backend.FollowURL(uid, url)
|
feed, err := h.backend.FollowURL(uid, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, feed)
|
respondJSON(w, feed)
|
||||||
|
@ -186,14 +186,14 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
url := values.Get("url")
|
url := values.Get("url")
|
||||||
err := h.backend.UnfollowURL(uid, url)
|
err := h.backend.UnfollowURL(uid, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, []string{})
|
respondJSON(w, []string{})
|
||||||
} else if action == "preview" {
|
} else if action == "preview" {
|
||||||
timeline, err := h.backend.PreviewURL(values.Get("url"))
|
timeline, err := h.backend.PreviewURL(values.Get("url"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respondJSON(w, timeline)
|
respondJSON(w, timeline)
|
||||||
|
@ -250,20 +250,20 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if len(markAsRead) > 0 {
|
if len(markAsRead) > 0 {
|
||||||
err := h.backend.MarkRead(channel, markAsRead)
|
err := h.backend.MarkRead(channel, markAsRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("No uids specified for mark read")
|
log.Println("No uids specified for mark read")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), 500)
|
http.Error(w, fmt.Sprintf("unknown method in timeline %s\n", method), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
respondJSON(w, []string{})
|
respondJSON(w, []string{})
|
||||||
} else {
|
} else {
|
||||||
http.Error(w, fmt.Sprintf("unknown action %s\n", action), 400)
|
http.Error(w, fmt.Sprintf("unknown action %s\n", action), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user