Handle internal server error using new custom template

This commit is contained in:
2024-05-14 11:35:15 +07:00
parent 420140918c
commit 43e16f1d79
17 changed files with 74 additions and 60 deletions

View File

@ -20,7 +20,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
userSession := r.Context().Value("user").(types.User)
files, err := db.DB.GetFiles(userSession.UserID.String())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
return
}
@ -37,7 +37,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
component := downloadView.Main("Download Page", filesData)
err = component.Render(r.Context(), w)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
log.Error(err.Error())
return
}

View File

@ -19,7 +19,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
fileID := r.PathValue("id")
file, err := db.DB.GetFile(fileID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
log.Error(err.Error())
return
}
@ -32,13 +32,13 @@ func GET(w http.ResponseWriter, r *http.Request) {
if filepath.Dir(saveFolder) != filepath.Join(basePath, file.OwnerID.String()) {
log.Error("invalid path")
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
return
}
openFile, err := os.OpenFile(filepath.Join(saveFolder, file.Name), os.O_RDONLY, 0)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
log.Error(err.Error())
return
}
@ -46,7 +46,7 @@ func GET(w http.ResponseWriter, r *http.Request) {
stat, err := openFile.Stat()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
w.WriteHeader(http.StatusInternalServerError)
log.Error(err.Error())
return
}