Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(simple_client): Add explicit ServiceUnavailable error type #207

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"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 All @@ -34,16 +39,15 @@
// when integration testing
func (c *SimpleCommitmentClient) Health() error {
url := c.cfg.URL + "/health"
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)

Check failure on line 42 in client/simple.go

View workflow job for this annotation

GitHub Actions / Linter

should rewrite http.NewRequestWithContext or add (*Request).WithContext (noctx)
if err != nil {
return err
}

resp, err := c.httpClient.Do(req)

Check failure on line 47 in client/simple.go

View workflow job for this annotation

GitHub Actions / Linter

response body must be closed (bodyclose)
if err != nil {
return err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("received bad status code: %d", resp.StatusCode)
Expand Down Expand Up @@ -81,7 +85,8 @@
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 +105,10 @@
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
Loading