summaryrefslogtreecommitdiff
path: root/internal/gtserror/error.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-09-27 11:15:53 +0000
committerLibravatar GitHub <noreply@github.com>2024-09-27 13:15:53 +0200
commit497ebd8c4e9db9a1351b841cc7fe04c960fb7987 (patch)
treea729e3e83cc60a85b70ac052b2549c9ffb4e3d7d /internal/gtserror/error.go
parent[chore] final bits of fiddling with solarized (#3364) (diff)
downloadgotosocial-497ebd8c4e9db9a1351b841cc7fe04c960fb7987.tar.xz
[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
Diffstat (limited to 'internal/gtserror/error.go')
-rw-r--r--internal/gtserror/error.go14
1 files changed, 14 insertions, 0 deletions
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