From c94edc0092e6c6098290d706ffa40ec862c85247 Mon Sep 17 00:00:00 2001 From: Kevin van Zonneveld Date: Fri, 29 Mar 2013 22:55:07 +0100 Subject: [PATCH] Implement more of the planned 404s --- src/cmd/tusd/http.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/cmd/tusd/http.go b/src/cmd/tusd/http.go index 9bf99f0..f644c2d 100644 --- a/src/cmd/tusd/http.go +++ b/src/cmd/tusd/http.go @@ -132,11 +132,15 @@ func postFiles(w http.ResponseWriter, r *http.Request) { } if contentRange.End != -1 { - if err := dataStore.WriteFileChunk(id, contentRange.Start, contentRange.End, r.Body); err != nil { - // @TODO: Could be a 404 as well + err := dataStore.WriteFileChunk(id, contentRange.Start, contentRange.End, r.Body) + if os.IsNotExist(err) { + reply(w, http.StatusNotFound, err.Error()) + return + } else if err != nil { reply(w, http.StatusInternalServerError, err.Error()) return } + } w.Header().Set("Location", "/files/"+id) @@ -154,18 +158,23 @@ func headFile(w http.ResponseWriter, r *http.Request, fileId string) { func getFile(w http.ResponseWriter, r *http.Request, fileId string) { meta, err := dataStore.GetFileMeta(fileId) - if err != nil { - // @TODO: Could be a 404 as well + if os.IsNotExist(err) { + reply(w, http.StatusNotFound, err.Error()) + return + } else if err != nil { reply(w, http.StatusInternalServerError, err.Error()) return } data, err := dataStore.ReadFile(fileId) - if err != nil { - // @TODO: Could be a 404 as well + if os.IsNotExist(err) { + reply(w, http.StatusNotFound, err.Error()) + return + } else if err != nil { reply(w, http.StatusInternalServerError, err.Error()) return } + defer data.Close() setFileHeaders(w, fileId) @@ -204,8 +213,11 @@ func putFile(w http.ResponseWriter, r *http.Request, fileId string) { // @TODO: Check that file exists - if err := dataStore.WriteFileChunk(fileId, start, end, r.Body); err != nil { - // @TODO: Could be a 404 as well + err = dataStore.WriteFileChunk(fileId, start, end, r.Body) + if os.IsNotExist(err) { + reply(w, http.StatusNotFound, err.Error()) + return + } else if err != nil { reply(w, http.StatusInternalServerError, err.Error()) return }