fix: update error logs

This commit is contained in:
Lakhan Samani
2021-12-17 21:12:53 +05:30
parent 537e08667a
commit 75a2b7effd
19 changed files with 29 additions and 44 deletions

View File

@@ -43,7 +43,7 @@ func (mgr *manager) AddSession(session Session) error {
DoNothing: true,
}).Create(&session)
if res.Error != nil {
log.Println(`Error saving session`, res.Error)
log.Println(`error saving session`, res.Error)
return res.Error
}
}
@@ -55,6 +55,7 @@ func (mgr *manager) AddSession(session Session) error {
sessionCollection, _ := mgr.arangodb.Collection(nil, Collections.Session)
_, err := sessionCollection.CreateDocument(nil, session)
if err != nil {
log.Println(`error saving session`, err)
return err
}
}

View File

@@ -159,9 +159,6 @@ func (mgr *manager) GetUserByEmail(email string) (User, error) {
}
defer cursor.Close()
log.Println("=> query:", query, bindVars)
log.Println("=> cursor:", cursor.Count())
for {
_, err := cursor.ReadDocument(nil, &user)
if driver.IsNoMoreDocuments(err) {

View File

@@ -35,7 +35,7 @@ func (mgr *manager) AddVerification(verification VerificationRequest) (Verificat
}).Create(&verification)
if result.Error != nil {
log.Println(`Error saving verification record`, result.Error)
log.Println(`error saving verification record`, result.Error)
return verification, result.Error
}
}
@@ -44,7 +44,6 @@ func (mgr *manager) AddVerification(verification VerificationRequest) (Verificat
verificationRequestCollection, _ := mgr.arangodb.Collection(nil, Collections.VerificationRequest)
meta, err := verificationRequestCollection.CreateDocument(nil, verification)
if err != nil {
log.Println("=> meta information for verification request:", meta.Key)
return verification, err
}
verification.Key = meta.Key
@@ -60,7 +59,7 @@ func (mgr *manager) GetVerificationRequests() ([]VerificationRequest, error) {
if IsSQL {
result := mgr.sqlDB.Find(&verificationRequests)
if result.Error != nil {
log.Println(result.Error)
log.Println("error getting verification requests:", result.Error)
return verificationRequests, result.Error
}
}
@@ -102,7 +101,7 @@ func (mgr *manager) GetVerificationByToken(token string) (VerificationRequest, e
result := mgr.sqlDB.Where("token = ?", token).First(&verification)
if result.Error != nil {
log.Println(`Error getting verification token:`, result.Error)
log.Println(`error getting verification request:`, result.Error)
return verification, result.Error
}
}
@@ -120,9 +119,7 @@ func (mgr *manager) GetVerificationByToken(token string) (VerificationRequest, e
defer cursor.Close()
for {
meta, err := cursor.ReadDocument(nil, &verification)
log.Println("=> arangodb verification by token:", verification, meta)
_, err := cursor.ReadDocument(nil, &verification)
if driver.IsNoMoreDocuments(err) {
break
@@ -141,7 +138,7 @@ func (mgr *manager) GetVerificationByEmail(email string) (VerificationRequest, e
result := mgr.sqlDB.Where("email = ?", email).First(&verification)
if result.Error != nil {
log.Println(`Error getting verification token:`, result.Error)
log.Println(`error getting verification token:`, result.Error)
return verification, result.Error
}
}
@@ -159,9 +156,7 @@ func (mgr *manager) GetVerificationByEmail(email string) (VerificationRequest, e
defer cursor.Close()
for {
meta, err := cursor.ReadDocument(nil, &verification)
log.Println("=> arangodb verification by token:", verification, meta)
_, err := cursor.ReadDocument(nil, &verification)
if driver.IsNoMoreDocuments(err) {
break
@@ -186,7 +181,6 @@ func (mgr *manager) DeleteVerificationRequest(verificationRequest VerificationRe
}
if IsArangoDB {
log.Println("vkey:", verificationRequest, verificationRequest.Key)
collection, _ := mgr.arangodb.Collection(nil, Collections.VerificationRequest)
_, err := collection.RemoveDocument(nil, verificationRequest.Key)
if err != nil {

View File

@@ -35,7 +35,7 @@ func InitEnv() {
err := godotenv.Load(envPath)
if err != nil {
log.Println("Error loading .env file")
log.Println("error loading .env file")
}
constants.VERSION = Version

View File

@@ -129,7 +129,7 @@ func processFacebookUserInfo(code string) (db.User, error) {
response, err := client.Do(req)
if err != nil {
log.Println("err processing facebook user info:", err)
log.Println("error processing facebook user info:", err)
return user, err
}
@@ -222,7 +222,6 @@ func OAuthCallbackHandler() gin.HandlerFunc {
// user exists in db, check if method was google
// if not append google to existing signup method and save it
log.Println("existing useR:", existingUser)
signupMethod := existingUser.SignupMethod
if !strings.Contains(signupMethod, provider) {
signupMethod = signupMethod + "," + provider

View File

@@ -19,7 +19,7 @@ func GinContextToContextMiddleware() gin.HandlerFunc {
if constants.AUTHORIZER_URL == "" {
url := location.Get(c)
constants.AUTHORIZER_URL = url.Scheme + "://" + c.Request.Host
log.Println("=> setting url:", constants.AUTHORIZER_URL)
log.Println("=> authorizer url:", constants.AUTHORIZER_URL)
}
ctx := context.WithValue(c.Request.Context(), "GinContextKey", c)
c.Request = c.Request.WithContext(ctx)
@@ -33,7 +33,6 @@ func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
origin := c.Request.Header.Get("Origin")
constants.APP_URL = origin
log.Println("=> APP_URL:", constants.APP_URL)
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")

View File

@@ -69,7 +69,7 @@ func AdminUpdateUser(ctx context.Context, params model.AdminUpdateUserInput) (*m
verificationType := enum.UpdateEmail.String()
token, err := utils.CreateVerificationToken(newEmail, verificationType)
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,
@@ -110,7 +110,7 @@ func AdminUpdateUser(ctx context.Context, params model.AdminUpdateUserInput) (*m
user, err = db.Mgr.UpdateUser(user)
if err != nil {
log.Println("Error updating user:", err)
log.Println("error updating user:", err)
return res, err
}

View File

@@ -31,7 +31,7 @@ func DeleteUser(ctx context.Context, params model.DeleteUserInput) (*model.Respo
err = db.Mgr.DeleteUser(user)
if err != nil {
log.Println("Err:", err)
log.Println("error deleting user:", err)
return res, err
}

View File

@@ -37,7 +37,7 @@ func ForgotPassword(ctx context.Context, params model.ForgotPasswordInput) (*mod
token, err := utils.CreateVerificationToken(params.Email, enum.ForgotPassword.String())
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,

View File

@@ -43,7 +43,7 @@ func Login(ctx context.Context, params model.LoginInput) (*model.AuthResponse, e
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(params.Password))
if err != nil {
log.Println("Compare password error:", err)
log.Println("compare password error:", err)
return res, fmt.Errorf(`invalid password`)
}
roles := constants.DEFAULT_ROLES

View File

@@ -94,7 +94,7 @@ func MagicLogin(ctx context.Context, params model.MagicLoginInput) (*model.Respo
user.SignupMethod = signupMethod
user, _ = db.Mgr.UpdateUser(user)
if err != nil {
log.Println("=> error updating user:", err)
log.Println("error updating user:", err)
}
}
@@ -103,7 +103,7 @@ func MagicLogin(ctx context.Context, params model.MagicLoginInput) (*model.Respo
verificationType := enum.MagicLink.String()
token, err := utils.CreateVerificationToken(params.Email, verificationType)
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,

View File

@@ -27,7 +27,7 @@ func ResendVerifyEmail(ctx context.Context, params model.ResendVerifyEmailInput)
token, err := utils.CreateVerificationToken(params.Email, verificationRequest.Identifier)
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,

View File

@@ -51,7 +51,7 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
// find user with email
existingUser, err := db.Mgr.GetUserByEmail(params.Email)
if err != nil {
log.Println("User with email " + params.Email + " not found")
log.Println("user with email " + params.Email + " not found")
}
if existingUser.EmailVerifiedAt > 0 {
@@ -103,7 +103,7 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
verificationType := enum.BasicAuthSignup.String()
token, err := utils.CreateVerificationToken(params.Email, verificationType)
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,

View File

@@ -109,7 +109,7 @@ func UpdateProfile(ctx context.Context, params model.UpdateProfileInput) (*model
verificationType := enum.UpdateEmail.String()
token, err := utils.CreateVerificationToken(newEmail, verificationType)
if err != nil {
log.Println(`Error generating token`, err)
log.Println(`error generating token`, err)
}
db.Mgr.AddVerification(db.VerificationRequest{
Token: token,
@@ -126,7 +126,7 @@ func UpdateProfile(ctx context.Context, params model.UpdateProfileInput) (*model
_, err = db.Mgr.UpdateUser(user)
if err != nil {
log.Println("Error updating user:", err)
log.Println("error updating user:", err)
return res, err
}
message := `Profile details updated successfully.`

View File

@@ -3,7 +3,6 @@ package resolvers
import (
"context"
"fmt"
"log"
"strings"
"time"
@@ -22,7 +21,6 @@ func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.Aut
}
verificationRequest, err := db.Mgr.GetVerificationByToken(params.Token)
log.Println("=> vf req:", verificationRequest)
if err != nil {
return res, fmt.Errorf(`invalid token`)
}

View File

@@ -1,7 +1,6 @@
package session
import (
"log"
"sync"
)
@@ -30,8 +29,6 @@ func (c *InMemoryStore) AddToken(userId, accessToken, refreshToken string) {
c.store[userId] = tempMap
}
log.Println(c.store)
c.mu.Unlock()
}

View File

@@ -47,7 +47,7 @@ func (c *RedisStore) GetToken(userId, accessToken string) string {
token := ""
res, err := c.store.HMGet(c.ctx, "authorizer_"+userId, accessToken).Result()
if err != nil {
log.Println("Error getting token from redis store:", err)
log.Println("error getting token from redis store:", err)
}
if len(res) > 0 && res[0] != nil {
token = fmt.Sprintf("%v", res[0])
@@ -66,7 +66,7 @@ func (c *RedisStore) GetSocialLoginState(key string) string {
state := ""
state, err := c.store.Get(c.ctx, key).Result()
if err != nil {
log.Println("Error getting token from redis store:", err)
log.Println("error getting token from redis store:", err)
}
return state

View File

@@ -96,7 +96,7 @@ func RemoveSocialLoginState(key string) {
func InitSession() {
if constants.REDIS_URL != "" {
log.Println("Using redis store to save sessions")
log.Println("using redis store to save sessions")
opt, err := redis.ParseURL(constants.REDIS_URL)
if err != nil {
log.Fatalln("Error parsing redis url:", err)
@@ -114,7 +114,7 @@ func InitSession() {
}
} else {
log.Println("Using in memory store to save sessions")
log.Println("using in memory store to save sessions")
SessionStoreObj.InMemoryStoreObj = &InMemoryStore{
store: map[string]map[string]string{},
socialLoginState: map[string]string{},

View File

@@ -64,12 +64,12 @@ func CreateAuthToken(user db.User, tokenType enum.TokenType, roles []string) (st
val, err := vm.Get("functionRes")
if err != nil {
log.Println("=> err custom access token script:", err)
log.Println("error getting custom access token script:", err)
} else {
extraPayload := make(map[string]interface{})
err = json.Unmarshal([]byte(fmt.Sprintf("%s", val)), &extraPayload)
if err != nil {
log.Println("Error converting accessTokenScript response to map:", err)
log.Println("error converting accessTokenScript response to map:", err)
} else {
for k, v := range extraPayload {
customClaims[k] = v