diff --git a/notacceptable.go b/notacceptable.go new file mode 100644 index 0000000..c274f6c --- /dev/null +++ b/notacceptable.go @@ -0,0 +1,36 @@ +package httpaccept + +import ( + "fmt" + "strings" +) + +var _ error = &internalNotAcceptable{} + +type internalNotAcceptable struct { + mediatypes []string +} + +func (receiver internalNotAcceptable) Error() string { + var mediatypes []string = receiver.mediatypes + + if len(mediatypes) < 1 { + return "httpaccept: none of the provided media-types are acceptable, because an empty list of media-types was provided" + } + + var buffer strings.Builder + buffer.WriteString("httpaccept: none of the provided media-types are acceptable —") + for _, mediatype := range mediatypes { + fmt.Fprintf(&buffer, " %q", mediatype) + } + + return buffer.String() +} + +func (internalNotAcceptable) ClientError() { + // Nothing here. +} + +func (internalNotAcceptable) NotAcceptable() { + // Nothing here. +}