From 74989d69c9ca78c895d84580ae2ce61e565336db Mon Sep 17 00:00:00 2001 From: "chris.lu@gmail.com" Date: Tue, 3 Jul 2012 06:46:26 +0000 Subject: [PATCH] add error handling when non-multipart request comes in git-svn-id: https://weed-fs.googlecode.com/svn/trunk@49 282b0af5-e82d-9cf1-ede4-77906d7719d0 --- weed-fs/src/cmd/weedvolume/weedvolume.go | 13 +++++++++---- weed-fs/src/pkg/storage/needle.go | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/weed-fs/src/cmd/weedvolume/weedvolume.go b/weed-fs/src/cmd/weedvolume/weedvolume.go index d2bd0daf6..e31b5cd0c 100644 --- a/weed-fs/src/cmd/weedvolume/weedvolume.go +++ b/weed-fs/src/cmd/weedvolume/weedvolume.go @@ -72,10 +72,15 @@ func PostHandler(w http.ResponseWriter, r *http.Request) { if e != nil { writeJson(w, r, e) } else { - ret := store.Write(volumeId, storage.NewNeedle(r)) - m := make(map[string]uint32) - m["size"] = ret - writeJson(w, r, m) + needle, ne := storage.NewNeedle(r) + if ne!=nil{ + writeJson(w, r, ne) + }else{ + ret := store.Write(volumeId, needle) + m := make(map[string]uint32) + m["size"] = ret + writeJson(w, r, m) + } } } func DeleteHandler(w http.ResponseWriter, r *http.Request) { diff --git a/weed-fs/src/pkg/storage/needle.go b/weed-fs/src/pkg/storage/needle.go index dff46b97a..b9d2a1300 100644 --- a/weed-fs/src/pkg/storage/needle.go +++ b/weed-fs/src/pkg/storage/needle.go @@ -20,12 +20,14 @@ type Needle struct { Padding []byte "Aligned to 8 bytes" } -func NewNeedle(r *http.Request) (n *Needle) { +func NewNeedle(r *http.Request) (n *Needle, e error) { n = new(Needle) form, fe := r.MultipartReader() if fe != nil { - log.Fatalf("MultipartReader [ERROR] %s\n", fe) + log.Printf("MultipartReader [ERROR] %s\n", fe) + e = fe + return } part, _ := form.NextPart() data, _ := ioutil.ReadAll(part)