Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions pkg/monobeam/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Client) UploadFile(ctx context.Context, objectType string, digest strin
if resp.StatusCode == http.StatusConflict {
return nil
} else if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return errors.New("Bad response from monobeam: " + strconv.Itoa(resp.StatusCode))
return errors.New("Bad response from monobeam for URL " + uploadUrl.String() + ": " + strconv.Itoa(resp.StatusCode))
}

// Decode the JSON payload
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *Client) UploadFile(ctx context.Context, objectType string, digest strin
}
defer beginResp.Body.Close()
if beginResp.StatusCode != http.StatusCreated {
return errors.New("Bad response from upload verification: " + strconv.Itoa(resp.StatusCode))
return errors.New("Bad response from upload verification for " + data.Uuid + ": " + strconv.Itoa(resp.StatusCode))
}

// Check verification status
Expand All @@ -143,7 +143,7 @@ func (c *Client) UploadFile(ctx context.Context, objectType string, digest strin
}
for i := 0; i < 100; i++ {
// Clone request so we use a fresh copy every loop
final, err := c.checkVerificationStatus(req.Clone(ctx))
final, err := c.checkVerificationStatus(req.Clone(ctx), data.Uuid)
if final {
return err
}
Expand All @@ -153,7 +153,7 @@ func (c *Client) UploadFile(ctx context.Context, objectType string, digest strin
return nil
}

func (c *Client) checkVerificationStatus(req *http.Request) (bool, error) {
func (c *Client) checkVerificationStatus(req *http.Request, uuid string) (bool, error) {
checkResp, err := c.client.Do(req)
if err != nil {
return true, err
Expand All @@ -173,7 +173,7 @@ func (c *Client) checkVerificationStatus(req *http.Request) (bool, error) {
if verificationStatus.Verified && verificationStatus.Complete {
return true, nil
}
return true, errors.New("Object failed to verify its hash.")
return true, errors.New(fmt.Sprintf("Object %s failed to verify its hash.", uuid))
}

return false, nil
Expand Down
21 changes: 21 additions & 0 deletions pkg/web/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ type FileChallengeAnswer struct {
ChallengeID string `json:"challenge_id"`
}

type VersionError struct {
Detail string `json:"detail"`
Pointer string `json:"pointer"`
}

type VersionErrors struct {
Detail string `json:"detail"`
Errors []VersionError `json:"errors"`
Status int `json:"status"`
Title string `json:"title"`
}

func NewClient(dockerCommand command.Command, client *http.Client) *Client {
return &Client{
dockerCommand: dockerCommand,
Expand Down Expand Up @@ -165,6 +177,15 @@ func (c *Client) PostNewVersion(ctx context.Context, image string, weights []Fil
defer resp.Body.Close()

if resp.StatusCode != http.StatusCreated {
if resp.StatusCode == http.StatusBadRequest {
decoder := json.NewDecoder(resp.Body)
var versionErrors VersionErrors
err = decoder.Decode(&versionErrors)
if err != nil {
return err
}
return errors.New(versionErrors.Detail)
}
return util.WrapError(ErrorBadResponseNewVersionEndpoint, strconv.Itoa(resp.StatusCode))
}

Expand Down
Loading