Replaced http.Error with 50x errors with web.Error50x().
This commit is contained in:
parent
6e9ad9323c
commit
a04adf7fa1
@ -75,7 +75,8 @@ 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)
|
||||||
http.Error(w, "Error reading an incoming file.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"Error reading an incoming file.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -94,7 +95,8 @@ 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)
|
||||||
http.Error(w, "A hash for the file cannot be computed.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"A hash for the file cannot be computed.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +113,8 @@ 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)
|
||||||
http.Error(w, "File cannot be written.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"File cannot be written.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fDst.Close()
|
defer fDst.Close()
|
||||||
@ -127,7 +130,8 @@ 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)
|
||||||
http.Error(w, "Failed to copy uploaded file to the storage.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"Failed to copy uploaded file to the storage.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +178,8 @@ 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)
|
||||||
http.Error(w, "Failed to open file to read.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"Failed to open file to read.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
@ -206,7 +211,8 @@ func (h *UploadHandlers) Delete(w http.ResponseWriter, r *http.Request) {
|
|||||||
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)
|
||||||
http.Error(w, "Failed to remove a file.", http.StatusInternalServerError)
|
web.Error50x(utils.MainSite(r.Host), http.StatusInternalServerError,
|
||||||
|
"Failed to remove a file.", w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user