Commit f96d5017 authored by acud's avatar acud Committed by GitHub

api: standardize error codes (#793)

* return 404
parent 3d8c3741
...@@ -68,7 +68,7 @@ func (s *server) bytesGetHandler(w http.ResponseWriter, r *http.Request) { ...@@ -68,7 +68,7 @@ func (s *server) bytesGetHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bytes: parse address %s: %v", nameOrHex, err) logger.Debugf("bytes: parse address %s: %v", nameOrHex, err)
logger.Error("bytes: parse address error") logger.Error("bytes: parse address error")
jsonhttp.BadRequest(w, "invalid address") jsonhttp.NotFound(w, nil)
return return
} }
......
...@@ -45,7 +45,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -45,7 +45,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bzz download: parse address %s: %v", nameOrHex, err) logger.Debugf("bzz download: parse address %s: %v", nameOrHex, err)
logger.Error("bzz download: parse address") logger.Error("bzz download: parse address")
jsonhttp.BadRequest(w, "invalid address") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -67,7 +67,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -67,7 +67,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bzz download: unmarshal entry %s: %v", address, err) logger.Debugf("bzz download: unmarshal entry %s: %v", address, err)
logger.Errorf("bzz download: unmarshal entry %s", address) logger.Errorf("bzz download: unmarshal entry %s", address)
jsonhttp.InternalServerError(w, "error unmarshaling entry") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -85,7 +85,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -85,7 +85,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bzz download: unmarshal metadata %s: %v", address, err) logger.Debugf("bzz download: unmarshal metadata %s: %v", address, err)
logger.Errorf("bzz download: unmarshal metadata %s", address) logger.Errorf("bzz download: unmarshal metadata %s", address)
jsonhttp.InternalServerError(w, "error unmarshaling metadata") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -100,7 +100,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -100,7 +100,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bzz download: not manifest %s: %v", address, err) logger.Debugf("bzz download: not manifest %s: %v", address, err)
logger.Error("bzz download: not manifest") logger.Error("bzz download: not manifest")
jsonhttp.BadRequest(w, "not manifest") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -176,7 +176,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -176,7 +176,7 @@ func (s *server) bzzDownloadHandler(w http.ResponseWriter, r *http.Request) {
jsonhttp.NotFound(w, "path address not found") jsonhttp.NotFound(w, "path address not found")
} else { } else {
jsonhttp.BadRequest(w, "invalid path address") jsonhttp.NotFound(w, nil)
} }
return return
} }
...@@ -203,7 +203,7 @@ func (s *server) serveManifestEntry(w http.ResponseWriter, r *http.Request, j fi ...@@ -203,7 +203,7 @@ func (s *server) serveManifestEntry(w http.ResponseWriter, r *http.Request, j fi
if err != nil { if err != nil {
logger.Debugf("bzz download: unmarshal file entry %s: %v", address, err) logger.Debugf("bzz download: unmarshal file entry %s: %v", address, err)
logger.Errorf("bzz download: unmarshal file entry %s", address) logger.Errorf("bzz download: unmarshal file entry %s", address)
jsonhttp.InternalServerError(w, "error unmarshaling file entry") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -221,7 +221,7 @@ func (s *server) serveManifestEntry(w http.ResponseWriter, r *http.Request, j fi ...@@ -221,7 +221,7 @@ func (s *server) serveManifestEntry(w http.ResponseWriter, r *http.Request, j fi
if err != nil { if err != nil {
logger.Debugf("bzz download: unmarshal metadata %s: %v", address, err) logger.Debugf("bzz download: unmarshal metadata %s: %v", address, err)
logger.Errorf("bzz download: unmarshal metadata %s", address) logger.Errorf("bzz download: unmarshal metadata %s", address)
jsonhttp.InternalServerError(w, "error unmarshaling metadata") jsonhttp.NotFound(w, nil)
return return
} }
......
...@@ -107,7 +107,7 @@ func (s *server) chunkGetHandler(w http.ResponseWriter, r *http.Request) { ...@@ -107,7 +107,7 @@ func (s *server) chunkGetHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
s.Logger.Debugf("chunk: parse chunk address %s: %v", nameOrHex, err) s.Logger.Debugf("chunk: parse chunk address %s: %v", nameOrHex, err)
s.Logger.Error("chunk: parse chunk address error") s.Logger.Error("chunk: parse chunk address error")
jsonhttp.BadRequest(w, "invalid chunk address") jsonhttp.NotFound(w, nil)
return return
} }
......
...@@ -237,7 +237,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -237,7 +237,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("file download: parse file address %s: %v", nameOrHex, err) logger.Debugf("file download: parse file address %s: %v", nameOrHex, err)
logger.Errorf("file download: parse file address %s", nameOrHex) logger.Errorf("file download: parse file address %s", nameOrHex)
jsonhttp.BadRequest(w, "invalid file address") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -261,7 +261,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -261,7 +261,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("file download: unmarshal entry %s: %v", address, err) logger.Debugf("file download: unmarshal entry %s: %v", address, err)
logger.Errorf("file download: unmarshal entry %s", address) logger.Errorf("file download: unmarshal entry %s", address)
jsonhttp.InternalServerError(w, "error unmarshaling entry") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -289,7 +289,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -289,7 +289,7 @@ func (s *server) fileDownloadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("file download: unmarshal metadata %s: %v", nameOrHex, err) logger.Debugf("file download: unmarshal metadata %s: %v", nameOrHex, err)
logger.Errorf("file download: unmarshal metadata %s", nameOrHex) logger.Errorf("file download: unmarshal metadata %s", nameOrHex)
jsonhttp.InternalServerError(w, "error unmarshaling metadata") jsonhttp.NotFound(w, nil)
return return
} }
...@@ -315,7 +315,7 @@ func (s *server) downloadHandler(w http.ResponseWriter, r *http.Request, referen ...@@ -315,7 +315,7 @@ func (s *server) downloadHandler(w http.ResponseWriter, r *http.Request, referen
if errors.Is(err, storage.ErrNotFound) { if errors.Is(err, storage.ErrNotFound) {
logger.Debugf("api download: not found %s: %v", reference, err) logger.Debugf("api download: not found %s: %v", reference, err)
logger.Error("api download: not found") logger.Error("api download: not found")
jsonhttp.NotFound(w, "not found") jsonhttp.NotFound(w, nil)
return return
} }
logger.Debugf("api download: invalid root chunk %s: %v", reference, err) logger.Debugf("api download: invalid root chunk %s: %v", reference, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment