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

adding detailed error handling to the omnivore integration #2242

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
35 changes: 30 additions & 5 deletions internal/integration/omnivore/omnivore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ type SaveUrlInput struct {
Url string `json:"url"`
}

type errorResponse struct {
Errors []struct {
Message string `json:"message"`
} `json:"errors"`
}

type successResponse struct {
Data struct {
SaveUrl struct {
Url string `json:"url"`
ClientRequestId string `json:"clientRequestId"`
} `json:"saveUrl"`
} `json:"data"`
}

type Client interface {
SaveUrl(url string) error
}
Expand Down Expand Up @@ -88,13 +103,23 @@ func (c *client) SaveUrl(url string) error {
return err
}

defer resp.Body.Close()
b, err = io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("omnivore: failed to parse response: %s", err)
}

if resp.StatusCode >= 400 {
defer resp.Body.Close()
b, err = io.ReadAll(resp.Body)
if err != nil {
return err
var errResponse errorResponse
if err = json.Unmarshal(b, &errResponse); err != nil {
return fmt.Errorf("omnivore: failed to save URL: status=%d %s", resp.StatusCode, string(b))
}
return fmt.Errorf("omnivore: failed to save URL: status=%d %s", resp.StatusCode, string(b))
return fmt.Errorf("omnivore: failed to save URL: status=%d %s", resp.StatusCode, errResponse.Errors[0].Message)
}

var successReponse successResponse
if err = json.Unmarshal(b, &successReponse); err != nil {
return fmt.Errorf("omnivore: failed to parse response, however the request appears successful, is the url correct?: status=%d %s", resp.StatusCode, string(b))
}

return nil
Expand Down
Loading