From 06b7ddf17578292391e90d07d4daf47e6845e037 Mon Sep 17 00:00:00 2001 From: James Mills Date: Sun, 22 Mar 2020 18:46:44 +1000 Subject: [PATCH] Add more error handling --- app/app.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index a43766c..4257bea 100644 --- a/app/app.go +++ b/app/app.go @@ -237,8 +237,19 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) { return } - os.Rename(tf.Name(), of) - os.Remove(fn) + if err := os.Rename(tf.Name(), of); err != nil { + err := fmt.Errorf("error renaming temporary file to output file: %w", err) + log.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + if err := os.Remove(fn); err != nil { + err := fmt.Errorf("error removing file: %w", err) + log.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } fmt.Fprintf(w, "Video successfully uploaded!") } else {