From 8929782f7d8099d320a7793addddf1257421901c Mon Sep 17 00:00:00 2001 From: Andrei Mihu Date: Sun, 15 Nov 2020 12:18:32 +0000 Subject: [PATCH] Fix unwanted log message. --- server/core_authenticate.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/core_authenticate.go b/server/core_authenticate.go index 67cd418da..687a02792 100644 --- a/server/core_authenticate.go +++ b/server/core_authenticate.go @@ -231,11 +231,12 @@ WHERE NOT EXISTS result, err := tx.ExecContext(ctx, query, userID, username, deviceID) if err != nil { - if err == sql.ErrNoRows { + e, ok := err.(pgx.PgError) + if err == sql.ErrNoRows || (ok && e.Code == dbErrorUniqueViolation && strings.Contains(e.Message, "user_device_pkey")) { // A concurrent write has inserted this device ID. logger.Info("Did not insert new user as device ID already exists.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create)) return StatusError(codes.Internal, "Error finding or creating user account.", err) - } else if e, ok := err.(pgx.PgError); ok && e.Code == dbErrorUniqueViolation && strings.Contains(e.Message, "users_username_key") { + } else if ok && e.Code == dbErrorUniqueViolation && strings.Contains(e.Message, "users_username_key") { return StatusError(codes.AlreadyExists, "Username is already in use.", err) } logger.Debug("Cannot find or create user with device ID.", zap.Error(err), zap.String("deviceID", deviceID), zap.String("username", username), zap.Bool("create", create)) -- GitLab