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

replace BadStatusCodeErr to BadStatusCodeError #2

Merged
merged 1 commit into from
Aug 28, 2020
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
12 changes: 10 additions & 2 deletions googp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import (
)

var (
BadStatusCodeErr = errors.New("Bad status code")
UnsupportedPageErr = errors.New("Unsupported page")
)

// BadStatusCodeError is an error returned when the status code is not 200 in Fetch.
type BadStatusCodeError struct {
StatusCode int
}

func (err BadStatusCodeError) Error() string {
return fmt.Sprintf("Bad status code (%d)", err.StatusCode)
}

// Fetch the content from the URL and parse OGP information.
func Fetch(rawurl string, i interface{}, opts ...ParserOpts) error {
res, err := http.Get(rawurl)
Expand All @@ -20,7 +28,7 @@ func Fetch(rawurl string, i interface{}, opts ...ParserOpts) error {
}

if res.StatusCode != 200 {
return fmt.Errorf("%w (%d)", BadStatusCodeErr, res.StatusCode)
return &BadStatusCodeError{StatusCode: res.StatusCode}
}

ct := res.Header.Get("Content-Type")
Expand Down