Skip to content

Commit

Permalink
chore(auth): better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Dec 18, 2024
1 parent 9b9e1db commit cf7b590
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions auth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,21 +627,26 @@ func deserializeCaddyAccessLog(dbpool db.DB, access *AccessLog) (*db.AnalyticsVi
// get user and namespace details from subdomain
props, err := shared.GetProjectFromSubdomain(subdomain)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not get project from subdomain %s: %w", subdomain, err)
}

// get user ID
user, err := dbpool.FindUserForName(props.Username)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not find user for name %s: %w", props.Username, err)
}

projectID := ""
postID := ""
if space == "pgs" { // figure out project ID
project, err := dbpool.FindProjectByName(user.ID, props.ProjectName)
if err != nil {
return nil, err
return nil, fmt.Errorf(
"could not find project by name, (user:%s, project:%s): %w",
user.ID,
props.ProjectName,
err,
)
}
projectID = project.ID
} else if space == "prose" { // figure out post ID
Expand All @@ -651,7 +656,13 @@ func deserializeCaddyAccessLog(dbpool db.DB, access *AccessLog) (*db.AnalyticsVi
cleanPath := strings.TrimPrefix(path, "/")
post, err := dbpool.FindPostWithSlug(cleanPath, user.ID, space)
if err != nil {
return nil, err
return nil, fmt.Errorf(
"could not find post with slug (path:%s, userId:%s, space:%s): %w",
cleanPath,
user.ID,
space,
err,
)
}
postID = post.ID
}
Expand All @@ -676,7 +687,7 @@ func accessLogToVisit(dbpool db.DB, line string) (*db.AnalyticsVisits, error) {
accessLog := AccessLog{}
err := json.Unmarshal([]byte(line), &accessLog)
if err != nil {
return nil, err
return nil, fmt.Errorf("could not unmarshal line: %w", err)
}

return deserializeCaddyAccessLog(dbpool, &accessLog)
Expand Down

0 comments on commit cf7b590

Please sign in to comment.