Skip to content

Commit

Permalink
chore(simple_client): Add explicit ServiceUnavailable error type (#207)
Browse files Browse the repository at this point in the history
* chore(simple_client): Add explicit ServiceUnavailable error type

* chore(simple_client): Add explicit ServiceUnavailable error type - bring back constructor

* chore(simple_client): Add explicit ServiceUnavailable error type - fix lint
  • Loading branch information
epociask authored Dec 3, 2024
1 parent aeeb503 commit aa290b1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"net/http"
)

var (
// 503 error type informing rollup to failover to other DA location
ErrServiceUnavailable = fmt.Errorf("eigenda service is unavailable")
)

// TODO: Add support for custom http client option
type Config struct {
URL string
Expand Down Expand Up @@ -81,7 +86,8 @@ func (c *SimpleCommitmentClient) GetData(ctx context.Context, comm []byte) ([]by
return b, nil
}

// SetData writes raw byte data to DA and returns the respective certificate
// SetData writes raw byte data to DA and returns the associated certificate
// which should be verified within the proxy
func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte, error) {
url := fmt.Sprintf("%s/put?commitment_mode=simple", c.cfg.URL)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(b))
Expand All @@ -100,6 +106,10 @@ func (c *SimpleCommitmentClient) SetData(ctx context.Context, b []byte) ([]byte,
return nil, err
}

if resp.StatusCode == http.StatusServiceUnavailable {
return nil, ErrServiceUnavailable
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to store data: %v, err = %s", resp.StatusCode, string(b))
}
Expand Down

0 comments on commit aa290b1

Please sign in to comment.