Commit 4b730a6f authored by Peter Mrekaj's avatar Peter Mrekaj Committed by GitHub

fix: http response of pinning non-existing address (#1712)

The POST pinning endpoint returns now 404 on non-existing chunks
instead of 500.
parent 5a012383
...@@ -463,6 +463,8 @@ paths: ...@@ -463,6 +463,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"403": "403":
$ref: "SwarmCommon.yaml#/components/responses/403" $ref: "SwarmCommon.yaml#/components/responses/403"
"404":
$ref: "SwarmCommon.yaml#/components/responses/404"
"500": "500":
$ref: "SwarmCommon.yaml#/components/responses/500" $ref: "SwarmCommon.yaml#/components/responses/500"
default: default:
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/pinning" "github.com/ethersphere/bee/pkg/pinning"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
...@@ -36,8 +37,11 @@ func (s *server) pinRootHash(w http.ResponseWriter, r *http.Request) { ...@@ -36,8 +37,11 @@ func (s *server) pinRootHash(w http.ResponseWriter, r *http.Request) {
return return
} }
err = s.pinning.CreatePin(r.Context(), ref, true) switch err = s.pinning.CreatePin(r.Context(), ref, true); {
if err != nil { case errors.Is(err, storage.ErrNotFound):
jsonhttp.NotFound(w, nil)
return
case err != nil:
s.logger.Debugf("pin root hash: creation of tracking pin for %q failed: %v", ref, err) s.logger.Debugf("pin root hash: creation of tracking pin for %q failed: %v", ref, err)
s.logger.Error("pin root hash: creation of tracking pin failed") s.logger.Error("pin root hash: creation of tracking pin failed")
jsonhttp.InternalServerError(w, nil) jsonhttp.InternalServerError(w, nil)
......
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