From 4920229a3b6e1d7dde536bc9ff766542b05d935c Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:26:56 +0200 Subject: Database updates (#144) * start moving some database stuff around * continue moving db stuff around * more fiddling * more updates * and some more * and yet more * i broke SOMETHING but what, it's a mystery * tidy up * vendor ttlcache * use ttlcache * fix up some tests * rename some stuff * little reminder * some more updates --- internal/db/pg/util.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 internal/db/pg/util.go (limited to 'internal/db/pg/util.go') diff --git a/internal/db/pg/util.go b/internal/db/pg/util.go new file mode 100644 index 000000000..17c09b720 --- /dev/null +++ b/internal/db/pg/util.go @@ -0,0 +1,25 @@ +package pg + +import ( + "strings" + + "github.com/go-pg/pg/v10" + "github.com/superseriousbusiness/gotosocial/internal/db" +) + +// processErrorResponse parses the given error and returns an appropriate DBError. +func processErrorResponse(err error) db.Error { + switch err { + case nil: + return nil + case pg.ErrNoRows: + return db.ErrNoEntries + case pg.ErrMultiRows: + return db.ErrMultipleEntries + default: + if strings.Contains(err.Error(), "duplicate key value violates unique constraint") { + return db.ErrAlreadyExists + } + return err + } +} -- cgit v1.2.3