Skip to content

Commit

Permalink
fix: api errors related to postage stamps (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
aloknerurkar committed Jun 10, 2021
1 parent 388256b commit 16551b8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 6 deletions.
8 changes: 8 additions & 0 deletions openapi/Swarm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse"
"400":
$ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"403":
$ref: "SwarmCommon.yaml#/components/responses/403"
"500":
Expand Down Expand Up @@ -153,6 +155,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/Status"
"400":
$ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"500":
$ref: "SwarmCommon.yaml#/components/responses/500"
default:
Expand Down Expand Up @@ -216,6 +220,8 @@ paths:
$ref: "SwarmCommon.yaml#/components/schemas/ReferenceResponse"
"400":
$ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"403":
$ref: "SwarmCommon.yaml#/components/responses/403"
"500":
Expand Down Expand Up @@ -589,6 +595,8 @@ paths:
description: Subscribed to topic
"400":
$ref: "SwarmCommon.yaml#/components/responses/400"
"402":
$ref: "SwarmCommon.yaml#/components/responses/402"
"500":
$ref: "SwarmCommon.yaml#/components/responses/500"
default:
Expand Down
6 changes: 6 additions & 0 deletions openapi/SwarmCommon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ components:
application/problem+json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"402":
description: Payment Required
content:
application/problem+json:
schema:
$ref: "#/components/schemas/ProblemDetails"
"403":
description: Forbidden
content:
Expand Down
9 changes: 8 additions & 1 deletion pkg/api/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
package api

import (
"errors"
"fmt"
"net/http"
"strings"

"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags"
Expand Down Expand Up @@ -70,7 +72,12 @@ func (s *server) bytesUploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
logger.Debugf("bytes upload: split write all: %v", err)
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
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/api/bzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethersphere/bee/pkg/file/loadsave"
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/manifest"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
Expand Down Expand Up @@ -119,7 +120,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store
if err != nil {
logger.Debugf("bzz upload file: file store, file %q: %v", fileName, err)
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
}

Expand Down Expand Up @@ -186,7 +192,12 @@ func (s *server) fileUploadHandler(w http.ResponseWriter, r *http.Request, store
if err != nil {
logger.Debugf("bzz upload file: manifest store, file %q: %v", fileName, err)
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
}
logger.Debugf("Manifest Reference: %s", manifestReference.String())
Expand Down
8 changes: 7 additions & 1 deletion pkg/api/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ethersphere/bee/pkg/netstore"

"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
Expand Down Expand Up @@ -104,7 +105,12 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
s.logger.Debugf("chunk upload: chunk write error: %v, addr %s", err, chunk.Address())
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
} else if len(seen) > 0 && seen[0] && tag != nil {
err := tag.Inc(tags.StateSeen)
Expand Down
8 changes: 7 additions & 1 deletion pkg/api/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/manifest"
"github.com/ethersphere/bee/pkg/postage"
"github.com/ethersphere/bee/pkg/sctx"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
Expand Down Expand Up @@ -86,7 +87,12 @@ func (s *server) dirUploadHandler(w http.ResponseWriter, r *http.Request, storer
if err != nil {
logger.Debugf("bzz upload dir: store dir err: %v", err)
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
}
if created {
Expand Down
8 changes: 7 additions & 1 deletion pkg/api/pss.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"io/ioutil"
"net/http"
"strings"
Expand Down Expand Up @@ -96,7 +97,12 @@ func (s *server) pssPostHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
s.logger.Debugf("pss send payload: %v. topic: %s", err, topicVar)
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
}

Expand Down

0 comments on commit 16551b8

Please sign in to comment.