[bugfix] fix media limit reader check (#3363)

* return nicer errors for frontend when media / emoji upload limit reached

* fix reader limit check

* add code comment
This commit is contained in:
kim
2024-09-27 11:15:53 +00:00
committed by GitHub
parent c1c8849322
commit 497ebd8c4e
3 changed files with 37 additions and 7 deletions

View File

@@ -40,8 +40,22 @@ const (
notRelevantKey
spamKey
notPermittedKey
limitReachedKey
)
// LimitReached indicates that this error was caused by
// some kind of limit being reached, e.g. media upload limit.
func LimitReached(err error) bool {
_, ok := errors.Value(err, limitReachedKey).(struct{})
return ok
}
// SetLimitReached will wrap the given error to store a "limit reached"
// flag, returning wrapped error. See LimitReached() for example use-cases.
func SetLimitReached(err error) error {
return errors.WithValue(err, limitReachedKey, struct{}{})
}
// IsUnretrievable indicates that a call to retrieve a resource
// (account, status, attachment, etc) could not be fulfilled, either
// because it was not found locally, or because some prerequisite