Browse Source

error handling

pull/2/head
Chris Lu 12 years ago
parent
commit
59ca65da3c
  1. 5
      weed-fs/src/cmd/weed/master.go
  2. 14
      weed-fs/src/cmd/weed/volume.go

5
weed-fs/src/cmd/weed/master.go

@ -45,7 +45,8 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
if commaSep > 0 { if commaSep > 0 {
vid = vid[0:commaSep] vid = vid[0:commaSep]
} }
volumeId, _ := storage.NewVolumeId(vid)
volumeId, err := storage.NewVolumeId(vid)
if err == nil {
machines := topo.Lookup(volumeId) machines := topo.Lookup(volumeId)
if machines != nil { if machines != nil {
ret := []map[string]string{} ret := []map[string]string{}
@ -54,9 +55,9 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
} }
writeJson(w, r, map[string]interface{}{"locations": ret}) writeJson(w, r, map[string]interface{}{"locations": ret})
} else { } else {
log.Println("Invalid volume id", volumeId)
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "}) writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
} }
}
} }
func dirAssignHandler(w http.ResponseWriter, r *http.Request) { func dirAssignHandler(w http.ResponseWriter, r *http.Request) {

14
weed-fs/src/cmd/weed/volume.go

@ -65,21 +65,29 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
func GetHandler(w http.ResponseWriter, r *http.Request) { func GetHandler(w http.ResponseWriter, r *http.Request) {
n := new(storage.Needle) n := new(storage.Needle)
vid, fid, ext := parseURLPath(r.URL.Path) vid, fid, ext := parseURLPath(r.URL.Path)
volumeId, _ := storage.NewVolumeId(vid)
volumeId, err := storage.NewVolumeId(vid)
if err != nil {
if *IsDebug {
log.Println("parsing error:", err, r.URL.Path)
}
return
}
n.ParsePath(fid) n.ParsePath(fid)
if *IsDebug { if *IsDebug {
log.Println("volume", volumeId, "reading", n) log.Println("volume", volumeId, "reading", n)
} }
if !store.HasVolume(volumeId) { if !store.HasVolume(volumeId) {
lookupResult, err := operation.Lookup(*server, volumeId)
lookupResult, err := operation.Lookup(*masterNode, volumeId)
if *IsDebug { if *IsDebug {
log.Println("volume", volumeId, "found on", lookupResult, "error", err) log.Println("volume", volumeId, "found on", lookupResult, "error", err)
} }
if err == nil { if err == nil {
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently) http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
} else { } else {
log.Println("lookup error:", err)
if *IsDebug {
log.Println("lookup error:", err, r.URL.Path)
}
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
return return

Loading…
Cancel
Save