diff --git a/googp.go b/googp.go index a6267d7..7c69b5d 100644 --- a/googp.go +++ b/googp.go @@ -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) @@ -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")