Commit 16551b8d authored by aloknerurkar's avatar aloknerurkar Committed by GitHub

fix: api errors related to postage stamps (#2037)

parent 388256b1
...@@ -59,6 +59,8 @@ paths: ...@@ -59,6 +59,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse" $ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse"
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"403": "403":
$ref: "SwarmCommon.yaml#/components/responses/403" $ref: "SwarmCommon.yaml#/components/responses/403"
"500": "500":
...@@ -153,6 +155,8 @@ paths: ...@@ -153,6 +155,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/Status" $ref: "SwarmCommon.yaml#/components/schemas/Status"
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"500": "500":
$ref: "SwarmCommon.yaml#/components/responses/500" $ref: "SwarmCommon.yaml#/components/responses/500"
default: default:
...@@ -216,6 +220,8 @@ paths: ...@@ -216,6 +220,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse" $ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse"
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"403": "403":
$ref: "SwarmCommon.yaml#/components/responses/403" $ref: "SwarmCommon.yaml#/components/responses/403"
"500": "500":
...@@ -589,6 +595,8 @@ paths: ...@@ -589,6 +595,8 @@ paths:
description: Subscribed to topic description: Subscribed to topic
"400": "400":
$ref: "SwarmCommon.yaml#/components/responses/400" $ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"500": "500":
$ref: "SwarmCommon.yaml#/components/responses/500" $ref: "SwarmCommon.yaml#/components/responses/500"
default: default:
......
...@@ -575,6 +575,12 @@ components: ...@@ -575,6 +575,12 @@ components:
application/problem+json: application/problem+json:
schema: schema:
$ref: "#/components/schemas/ProblemDetails" $ref: "#/components/schemas/ProblemDetails"
"402":
description: Payment Required
content:
application/problem+json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"403": "403":
description: Forbidden description: Forbidden
content: content:
......
...@@ -5,11 +5,13 @@ ...@@ -5,11 +5,13 @@
package api package api
import ( import (
"errors"
"fmt" "fmt"
"net/http" "net/http"
"strings" "strings"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx" "github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags" "github.com/ethersphere/bee/pkg/tags"
...@@ -70,7 +72,12 @@ func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -70,7 +72,12 @@ func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
logger.Debugf("bytes upload: split write all: %v", err) logger.Debugf("bytes upload: split write all: %v", err)
logger.Error("bytes upload: split write all") logger.Error("bytes upload: split write all")
jsonhttp.InternalServerError(w, nil) switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, nil)
}
return return
} }
......
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"github.com/ethersphere/bee/pkg/file/loadsave" "github.com/ethersphere/bee/pkg/file/loadsave"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/manifest" "github.com/ethersphere/bee/pkg/manifest"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx" "github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
...@@ -119,7 +120,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store ...@@ -119,7 +120,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store
if err != nil { if err != nil {
logger.Debugf("bzz upload file: file store, file %q: %v", fileName, err) logger.Debugf("bzz upload file: file store, file %q: %v", fileName, err)
logger.Errorf("bzz upload file: file store, file %q", fileName) logger.Errorf("bzz upload file: file store, file %q", fileName)
jsonhttp.InternalServerError(w, errFileStore) switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, errFileStore)
}
return return
} }
...@@ -186,7 +192,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store ...@@ -186,7 +192,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store
if err != nil { if err != nil {
logger.Debugf("bzz upload file: manifest store, file %q: %v", fileName, err) logger.Debugf("bzz upload file: manifest store, file %q: %v", fileName, err)
logger.Errorf("bzz upload file: manifest store, file %q", fileName) logger.Errorf("bzz upload file: manifest store, file %q", fileName)
jsonhttp.InternalServerError(w, nil) switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, nil)
}
return return
} }
logger.Debugf("Manifest Reference: %s", manifestReference.String()) logger.Debugf("Manifest Reference: %s", manifestReference.String())
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"github.com/ethersphere/bee/pkg/netstore" "github.com/ethersphere/bee/pkg/netstore"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx" "github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
...@@ -104,7 +105,12 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) { ...@@ -104,7 +105,12 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
s.logger.Debugf("chunk upload: chunk write error: %v, addr %s", err, chunk.Address()) s.logger.Debugf("chunk upload: chunk write error: %v, addr %s", err, chunk.Address())
s.logger.Error("chunk upload: chunk write error") s.logger.Error("chunk upload: chunk write error")
jsonhttp.BadRequest(w, "chunk write error") switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, "chunk write error")
}
return return
} else if len(seen) > 0 && seen[0] && tag != nil { } else if len(seen) > 0 && seen[0] && tag != nil {
err := tag.Inc(tags.StateSeen) err := tag.Inc(tags.StateSeen)
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/logging" "github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/manifest" "github.com/ethersphere/bee/pkg/manifest"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx" "github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
...@@ -86,7 +87,12 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request, storer ...@@ -86,7 +87,12 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request, storer
if err != nil { if err != nil {
logger.Debugf("bzz upload dir: store dir err: %v", err) logger.Debugf("bzz upload dir: store dir err: %v", err)
logger.Errorf("bzz upload dir: store dir") logger.Errorf("bzz upload dir: store dir")
jsonhttp.InternalServerError(w, errDirectoryStore) switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, errDirectoryStore)
}
return return
} }
if created { if created {
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/hex" "encoding/hex"
"errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
...@@ -96,7 +97,12 @@ func (s *server) pssPostHandler(w http.ResponseWriter, r *http.Request) { ...@@ -96,7 +97,12 @@ func (s *server) pssPostHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
s.logger.Debugf("pss send payload: %v. topic: %s", err, topicVar) s.logger.Debugf("pss send payload: %v. topic: %s", err, topicVar)
s.logger.Error("pss send payload") s.logger.Error("pss send payload")
jsonhttp.InternalServerError(w, nil) switch {
case errors.Is(err, postage.ErrBucketFull):
jsonhttp.PaymentRequired(w, "batch is overissued")
default:
jsonhttp.InternalServerError(w, nil)
}
return return
} }
......
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