From 497ebd8c4e9db9a1351b841cc7fe04c960fb7987 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Fri, 27 Sep 2024 11:15:53 +0000 Subject: [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 --- internal/gtserror/error.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'internal/gtserror/error.go') diff --git a/internal/gtserror/error.go b/internal/gtserror/error.go index a39b5475c..bd83a8dc8 100644 --- a/internal/gtserror/error.go +++ b/internal/gtserror/error.go @@ -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 -- cgit v1.2.3