mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-12-08 14:36:32 +01:00
268f252e0d
* start implementing remote emoji fetcher * update status where pk * aaa * tidy up a little * check size limits for emojis * thank you linter, i love you <3 * update swagger docs * add emoji dereference test * make emoji max sizes configurable * normalize db.ErrAlreadyExists
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package bundb
|
|
|
|
import (
|
|
"github.com/jackc/pgconn"
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
|
"modernc.org/sqlite"
|
|
sqlite3 "modernc.org/sqlite/lib"
|
|
)
|
|
|
|
// processPostgresError processes an error, replacing any postgres specific errors with our own error type
|
|
func processPostgresError(err error) db.Error {
|
|
// Attempt to cast as postgres
|
|
pgErr, ok := err.(*pgconn.PgError)
|
|
if !ok {
|
|
return err
|
|
}
|
|
|
|
// Handle supplied error code:
|
|
// (https://www.postgresql.org/docs/10/errcodes-appendix.html)
|
|
switch pgErr.Code {
|
|
case "23505" /* unique_violation */ :
|
|
return db.ErrAlreadyExists
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
// processSQLiteError processes an error, replacing any sqlite specific errors with our own error type
|
|
func processSQLiteError(err error) db.Error {
|
|
// Attempt to cast as sqlite
|
|
sqliteErr, ok := err.(*sqlite.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
|
|
// Handle supplied error code:
|
|
switch sqliteErr.Code() {
|
|
case sqlite3.SQLITE_CONSTRAINT_UNIQUE, sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY:
|
|
return db.ErrAlreadyExists
|
|
default:
|
|
return err
|
|
}
|
|
}
|