package mrktplaats import ( "errors" "fmt" ) // APIError is returned when the API responds with a non-2xx status code. type APIError struct { StatusCode int Body []byte } func (e *APIError) Error() string { return fmt.Sprintf("mrktplaats: API error %d: %s", e.StatusCode, string(e.Body)) } // IsNotFound reports whether err is an API 404 response. func IsNotFound(err error) bool { var apiErr *APIError return errors.As(err, &apiErr) && apiErr.StatusCode == 404 } // IsUnauthorized reports whether err is an API 401 response. func IsUnauthorized(err error) bool { var apiErr *APIError return errors.As(err, &apiErr) && apiErr.StatusCode == 401 }