mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-02-17 14:18:26 +00:00
* add ensureUserIsAuthorizedOrRedirect to /oauth/authorize * adding authorization (email confirm, account approve, etc) to TokenCheck * revert un-needed changes to signin.go * oops what happened here * error css * add account.SuspendedAt check * remove redundant checks from oauth util Authed function * wip tests * tests passing * stop stripping useful information from ErrAlreadyExists * that feeling of scraping the dryer LINT off the screen * oops I didn't mean to get rid of this NewTestRouter function * make tests work with recorder * re-add ConfigureTemplatesWithGin to handle template path err Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
43 lines
1 KiB
Go
43 lines
1 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.NewErrAlreadyExists(pgErr.Message)
|
|
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:
|
|
return db.NewErrAlreadyExists(err.Error())
|
|
default:
|
|
return err
|
|
}
|
|
}
|