Unify error messages
This commit is contained in:
11
link.go
11
link.go
@@ -2,7 +2,6 @@ package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
@@ -27,28 +26,28 @@ func NewLink(href string) *Link {
|
||||
// error.
|
||||
func (l *Link) Check() error {
|
||||
if l.Href == "" {
|
||||
return errors.New("href attribute of link empty")
|
||||
return fmt.Errorf("href attribute of link %v empty", l)
|
||||
} else {
|
||||
if !isValidIRI(l.Href) {
|
||||
return fmt.Errorf("href attribute %v of link not correctly formatted", l.Href)
|
||||
return fmt.Errorf("href attribute of link %v not correctly formatted", l)
|
||||
}
|
||||
}
|
||||
|
||||
if l.Rel != "" {
|
||||
if strings.Contains(l.Rel, ":") && !isValidIRI(IRI(l.Rel)) {
|
||||
return fmt.Errorf("rel attribute %v of link %v not correctly formatted", l.Rel, l.Href)
|
||||
return fmt.Errorf("rel attribute of link %v not correctly formatted", l)
|
||||
}
|
||||
}
|
||||
|
||||
if l.Type != "" {
|
||||
if !isValidMediaType(string(l.Type)) {
|
||||
return fmt.Errorf("type attribute %v of link %v invalid media type", l.Type, l.Href)
|
||||
return fmt.Errorf("type attribute of link %v invalid media type", l)
|
||||
}
|
||||
}
|
||||
|
||||
if l.HrefLang != "" {
|
||||
if !isValidLanguageTag(l.HrefLang) {
|
||||
return fmt.Errorf("hreflang attribute %v of link %v invalid language tag", l.Type, l.HrefLang)
|
||||
return fmt.Errorf("hreflang attribute of link %v invalid language tag", l)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user