A new Error() handler used.
This commit is contained in:
parent
185bd80750
commit
fb9cee2c0a
@ -67,7 +67,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if err := r.ParseMultipartForm(fMaxSizeBytes); err != nil {
|
if err := r.ParseMultipartForm(fMaxSizeBytes); err != nil {
|
||||||
log.Println("failed to parse upload form:", err)
|
log.Println("failed to parse upload form:", err)
|
||||||
http.Error(w, "Failed to parse upload form.", http.StatusExpectationFailed)
|
Error(w, r, http.StatusExpectationFailed, "Failed to parse upload form.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,8 +75,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to open incoming file:", err)
|
log.Println("failed to open incoming file:", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "Error reading an incoming file.")
|
||||||
"Error reading an incoming file.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -95,8 +94,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
s256 := sha256.New()
|
s256 := sha256.New()
|
||||||
if _, err := io.Copy(s256, f); err != nil {
|
if _, err := io.Copy(s256, f); err != nil {
|
||||||
log.Println("failed to compute a SHA-256 hash:", err)
|
log.Println("failed to compute a SHA-256 hash:", err)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "A hash for the file cannot be computed.")
|
||||||
"A hash for the file cannot be computed.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +111,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
fDst, err := os.Create(fPath)
|
fDst, err := os.Create(fPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to open file for writing", err)
|
log.Println("failed to open file for writing", err)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "File cannot be written.")
|
||||||
"File cannot be written.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fDst.Close()
|
defer fDst.Close()
|
||||||
@ -130,8 +127,7 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
_, err = io.Copy(fDst, f)
|
_, err = io.Copy(fDst, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to copy uploaded file to destination:", err)
|
log.Println("failed to copy uploaded file to destination:", err)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "Failed to copy uploaded file to the storage.")
|
||||||
"Failed to copy uploaded file to the storage.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +163,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stat, err := os.Stat(path)
|
stat, err := os.Stat(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
NotFound(w, r)
|
Error(w, r, http.StatusNotFound, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,8 +174,7 @@ func (h *UploadHandlers) Download(w http.ResponseWriter, r *http.Request) {
|
|||||||
fd, err := os.Open(path)
|
fd, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to open file to read:", err)
|
log.Println("failed to open file to read:", err)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "Failed to open file to read.")
|
||||||
"Failed to open file to read.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
@ -204,15 +199,14 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
NotFound(w, r)
|
Error(w, r, http.StatusNotFound, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(path)
|
err = os.Remove(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to remove a file:", err)
|
log.Println("failed to remove a file:", err)
|
||||||
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
Error(w, r, http.StatusInternalServerError, "Failed to remove a file.")
|
||||||
"Failed to remove a file.", w)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user