From 143ccfc05c1a2d7e126c4be75c654c3a69a36c2e Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Tue, 13 Jul 2021 10:58:56 -0400 Subject: [PATCH] try fetching device before account to reduce orphaned accounts --- cmd/apollo-api/accounts.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/apollo-api/accounts.go b/cmd/apollo-api/accounts.go index 27addd5..695323c 100644 --- a/cmd/apollo-api/accounts.go +++ b/cmd/apollo-api/accounts.go @@ -43,7 +43,7 @@ func (app *application) upsertAccountHandler(w http.ResponseWriter, r *http.Requ if err != nil { app.logger.WithFields(logrus.Fields{ "err": err, - }).Info("failed to grab user details") + }).Info("failed to grab user details from Reddit") app.errorResponse(w, r, 500, err.Error()) return } @@ -59,21 +59,21 @@ func (app *application) upsertAccountHandler(w http.ResponseWriter, r *http.Requ // Set account ID from Reddit a.AccountID = me.ID - // Upsert account - if err := app.models.Accounts.Upsert(a); err != nil { - app.logger.WithFields(logrus.Fields{ - "err": err, - }).Info("failed updating account in database") - app.errorResponse(w, r, 500, err.Error()) - return - } - // Associate d, err := app.models.Devices.GetByAPNSToken(ps.ByName("apns")) if err != nil { app.logger.WithFields(logrus.Fields{ "err": err, - }).Info("failed fetching account devices") + }).Info("failed fetching device from database") + app.errorResponse(w, r, 500, err.Error()) + return + } + + // Upsert account + if err := app.models.Accounts.Upsert(a); err != nil { + app.logger.WithFields(logrus.Fields{ + "err": err, + }).Info("failed updating account in database") app.errorResponse(w, r, 500, err.Error()) return }