mirror of https://github.com/jlelse/GoBlog
Add missing error returns
This commit is contained in:
parent
954c3be6c3
commit
899caf9aaa
25
micropub.go
25
micropub.go
|
@ -116,18 +116,20 @@ func serveMicropubPost(w http.ResponseWriter, r *http.Request) {
|
||||||
var p *post
|
var p *post
|
||||||
if ct := r.Header.Get(contentType); strings.Contains(ct, contentTypeWWWForm) || strings.Contains(ct, contentTypeMultipartForm) {
|
if ct := r.Header.Get(contentType); strings.Contains(ct, contentTypeWWWForm) || strings.Contains(ct, contentTypeMultipartForm) {
|
||||||
var err error
|
var err error
|
||||||
r.ParseForm()
|
|
||||||
if strings.Contains(ct, contentTypeMultipartForm) {
|
if strings.Contains(ct, contentTypeMultipartForm) {
|
||||||
err := r.ParseMultipartForm(0)
|
err = r.ParseMultipartForm(0)
|
||||||
if err != nil {
|
} else {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
err = r.ParseForm()
|
||||||
return
|
}
|
||||||
}
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if action := micropubAction(r.Form.Get("action")); action != "" {
|
if action := micropubAction(r.Form.Get("action")); action != "" {
|
||||||
u, err := url.Parse(r.Form.Get("url"))
|
u, err := url.Parse(r.Form.Get("url"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if action == actionDelete {
|
if action == actionDelete {
|
||||||
micropubDelete(w, r, u)
|
micropubDelete(w, r, u)
|
||||||
|
@ -152,6 +154,7 @@ func serveMicropubPost(w http.ResponseWriter, r *http.Request) {
|
||||||
u, err := url.Parse(parsedMfItem.URL)
|
u, err := url.Parse(parsedMfItem.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if parsedMfItem.Action == actionDelete {
|
if parsedMfItem.Action == actionDelete {
|
||||||
micropubDelete(w, r, u)
|
micropubDelete(w, r, u)
|
||||||
|
@ -175,6 +178,7 @@ func serveMicropubPost(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
if !strings.Contains(r.Context().Value("scope").(string), "create") {
|
if !strings.Contains(r.Context().Value("scope").(string), "create") {
|
||||||
http.Error(w, "create scope missing", http.StatusForbidden)
|
http.Error(w, "create scope missing", http.StatusForbidden)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
err := p.create()
|
err := p.create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -412,19 +416,20 @@ func (p *post) computeExtraPostParameters() error {
|
||||||
func micropubDelete(w http.ResponseWriter, r *http.Request, u *url.URL) {
|
func micropubDelete(w http.ResponseWriter, r *http.Request, u *url.URL) {
|
||||||
if !strings.Contains(r.Context().Value("scope").(string), "delete") {
|
if !strings.Contains(r.Context().Value("scope").(string), "delete") {
|
||||||
http.Error(w, "delete scope missing", http.StatusForbidden)
|
http.Error(w, "delete scope missing", http.StatusForbidden)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
err := deletePost(u.Path)
|
if err := deletePost(u.Path); err != nil {
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
} else {
|
return
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
}
|
}
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func micropubUpdate(w http.ResponseWriter, r *http.Request, u *url.URL, mf *microformatItem) {
|
func micropubUpdate(w http.ResponseWriter, r *http.Request, u *url.URL, mf *microformatItem) {
|
||||||
if !strings.Contains(r.Context().Value("scope").(string), "update") {
|
if !strings.Contains(r.Context().Value("scope").(string), "update") {
|
||||||
http.Error(w, "update scope missing", http.StatusForbidden)
|
http.Error(w, "update scope missing", http.StatusForbidden)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
p, err := getPost(u.Path)
|
p, err := getPost(u.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -23,6 +23,7 @@ const micropubMediaSubPath = "/media"
|
||||||
func serveMicropubMedia(w http.ResponseWriter, r *http.Request) {
|
func serveMicropubMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
if !strings.Contains(r.Context().Value("scope").(string), "media") {
|
if !strings.Contains(r.Context().Value("scope").(string), "media") {
|
||||||
http.Error(w, "media scope missing", http.StatusForbidden)
|
http.Error(w, "media scope missing", http.StatusForbidden)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if appConfig.Micropub.MediaStorage == nil {
|
if appConfig.Micropub.MediaStorage == nil {
|
||||||
http.Error(w, "Not configured", http.StatusNotImplemented)
|
http.Error(w, "Not configured", http.StatusNotImplemented)
|
||||||
|
|
|
@ -234,6 +234,7 @@ func render(w http.ResponseWriter, template string, data *renderData) {
|
||||||
err := templates[template].ExecuteTemplate(&buffer, template, data)
|
err := templates[template].ExecuteTemplate(&buffer, template, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
// Set content type (needed for minification middleware
|
// Set content type (needed for minification middleware
|
||||||
w.Header().Set(contentType, contentTypeHTMLUTF8)
|
w.Header().Set(contentType, contentTypeHTMLUTF8)
|
||||||
|
|
|
@ -14,6 +14,7 @@ func serveSitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
posts, err := getPosts(&postsRequestConfig{})
|
posts, err := getPosts(&postsRequestConfig{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
sm := sitemap.New()
|
sm := sitemap.New()
|
||||||
sm.Minify = true
|
sm.Minify = true
|
||||||
|
|
Loading…
Reference in New Issue