improve error logging
parent
7ebdadbbab
commit
01e1715bc7
|
@ -28,7 +28,6 @@ func DELETE(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
|
||||||
|
|
||||||
// Check for errors
|
// Check for errors
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return 500, err
|
return 500, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -63,7 +63,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||||
if _, err := os.Stat(archetype + ".markdown"); err == nil {
|
if _, err := os.Stat(archetype + ".markdown"); err == nil {
|
||||||
err = utils.CopyFile(archetype+".markdown", filename)
|
err = utils.CopyFile(archetype+".markdown", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +76,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||||
if _, err := os.Stat(archetype + ".md"); err == nil {
|
if _, err := os.Stat(archetype + ".md"); err == nil {
|
||||||
err = utils.CopyFile(archetype+".md", filename)
|
err = utils.CopyFile(archetype+".md", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +88,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config) (int, error)
|
||||||
|
|
||||||
wf, err := os.Create(filename)
|
wf, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +103,6 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
|
||||||
// Parse the multipart form in the request
|
// Parse the multipart form in the request
|
||||||
err := r.ParseMultipartForm(100000)
|
err := r.ParseMultipartForm(100000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,20 +113,17 @@ func upload(w http.ResponseWriter, r *http.Request, c *config.Config) (int, erro
|
||||||
// Open the first file
|
// Open the first file
|
||||||
var infile multipart.File
|
var infile multipart.File
|
||||||
if infile, err = hdr.Open(); nil != err {
|
if infile, err = hdr.Open(); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the file
|
// Create the file
|
||||||
var outfile *os.File
|
var outfile *os.File
|
||||||
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
|
if outfile, err = os.Create(c.Path + r.URL.Path + hdr.Filename); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the file content
|
// Copy the file content
|
||||||
if _, err = io.Copy(outfile, infile); nil != err {
|
if _, err = io.Copy(outfile, infile); nil != err {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
case "frontmatter-only":
|
case "frontmatter-only":
|
||||||
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
|
f, code, err := parseFrontMatterOnlyFile(rawFile, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +47,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
case "complete":
|
case "complete":
|
||||||
f, code, err := parseCompleteFile(r, c, rawFile, filename)
|
f, code, err := parseCompleteFile(r, c, rawFile, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +59,6 @@ func POST(w http.ResponseWriter, r *http.Request, c *config.Config, filename str
|
||||||
err := ioutil.WriteFile(filename, file, 0666)
|
err := ioutil.WriteFile(filename, file, 0666)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
5
hugo.go
5
hugo.go
|
@ -7,6 +7,7 @@
|
||||||
package hugo
|
package hugo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -141,6 +142,10 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
||||||
utils.Run(h.Config)
|
utils.Run(h.Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ func Run(c *config.Config) {
|
||||||
viper.Reset()
|
viper.Reset()
|
||||||
commands.HugoCmd.ParseFlags(c.Args)
|
commands.HugoCmd.ParseFlags(c.Args)
|
||||||
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
|
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
|
||||||
log.Print(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue