Implement more of the planned 404s

This commit is contained in:
Kevin van Zonneveld 2013-03-29 22:55:07 +01:00
parent 15c3a6f898
commit c94edc0092
1 changed files with 20 additions and 8 deletions

View File

@ -132,11 +132,15 @@ func postFiles(w http.ResponseWriter, r *http.Request) {
} }
if contentRange.End != -1 { if contentRange.End != -1 {
if err := dataStore.WriteFileChunk(id, contentRange.Start, contentRange.End, r.Body); err != nil { err := dataStore.WriteFileChunk(id, contentRange.Start, contentRange.End, r.Body)
// @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()) reply(w, http.StatusInternalServerError, err.Error())
return return
} }
} }
w.Header().Set("Location", "/files/"+id) 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) { func getFile(w http.ResponseWriter, r *http.Request, fileId string) {
meta, err := dataStore.GetFileMeta(fileId) meta, err := dataStore.GetFileMeta(fileId)
if err != nil { if os.IsNotExist(err) {
// @TODO: Could be a 404 as well reply(w, http.StatusNotFound, err.Error())
return
} else if err != nil {
reply(w, http.StatusInternalServerError, err.Error()) reply(w, http.StatusInternalServerError, err.Error())
return return
} }
data, err := dataStore.ReadFile(fileId) data, err := dataStore.ReadFile(fileId)
if err != nil { if os.IsNotExist(err) {
// @TODO: Could be a 404 as well reply(w, http.StatusNotFound, err.Error())
return
} else if err != nil {
reply(w, http.StatusInternalServerError, err.Error()) reply(w, http.StatusInternalServerError, err.Error())
return return
} }
defer data.Close() defer data.Close()
setFileHeaders(w, fileId) setFileHeaders(w, fileId)
@ -204,8 +213,11 @@ func putFile(w http.ResponseWriter, r *http.Request, fileId string) {
// @TODO: Check that file exists // @TODO: Check that file exists
if err := dataStore.WriteFileChunk(fileId, start, end, r.Body); err != nil { err = dataStore.WriteFileChunk(fileId, start, end, r.Body)
// @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()) reply(w, http.StatusInternalServerError, err.Error())
return return
} }