Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package feeds
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
)
|
|
|
|
// ErrFormatMismatch is returned when the public export URL extension does not
|
|
// match the feed's configured format. Public HTTP handlers must map this to the
|
|
// same opaque 404 as an unknown token (no existence oracle).
|
|
var ErrFormatMismatch = errors.New("format mismatch")
|
|
|
|
// ErrNotFound is returned when a company-scoped feed (or related row) is missing.
|
|
var ErrNotFound = errors.New("not found")
|
|
|
|
// clientError is a validation/business message safe to return to API clients.
|
|
type clientError struct {
|
|
msg string
|
|
}
|
|
|
|
func (e *clientError) Error() string { return e.msg }
|
|
|
|
// ClientMsg marks a message as safe to expose in HTTP 4xx responses.
|
|
func ClientMsg(msg string) error {
|
|
return &clientError{msg: msg}
|
|
}
|
|
|
|
// ClientError reports whether err is a known client-facing feeds error.
|
|
func ClientError(err error) (msg string, ok bool) {
|
|
if err == nil {
|
|
return "", false
|
|
}
|
|
var ce *clientError
|
|
if errors.As(err, &ce) {
|
|
return ce.msg, true
|
|
}
|
|
switch {
|
|
case errors.Is(err, ErrNotFound), errors.Is(err, pgx.ErrNoRows):
|
|
return "not found", true
|
|
case errors.Is(err, ErrFormatMismatch),
|
|
errors.Is(err, errURLRequired),
|
|
errors.Is(err, errURLScheme),
|
|
errors.Is(err, errURLPrivate),
|
|
errors.Is(err, errURLFTP),
|
|
errors.Is(err, errDownloadTooLarge),
|
|
errors.Is(err, errParseTooManyRows),
|
|
errors.Is(err, errSourceRequired),
|
|
errors.Is(err, errLocalSource):
|
|
return err.Error(), true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
// IsNotFound reports whether err means a missing feed/resource.
|
|
func IsNotFound(err error) bool {
|
|
return errors.Is(err, ErrNotFound) || errors.Is(err, pgx.ErrNoRows)
|
|
}
|