- commit
- cf7b590
- parent
- 9b9e1db
- author
- Eric Bower
- date
- 2024-12-18 02:27:31 +0000 UTC
chore(auth): better logging
1 files changed,
+16,
-5
+16,
-5
1@@ -627,13 +627,13 @@ func deserializeCaddyAccessLog(dbpool db.DB, access *AccessLog) (*db.AnalyticsVi
2 // get user and namespace details from subdomain
3 props, err := shared.GetProjectFromSubdomain(subdomain)
4 if err != nil {
5- return nil, err
6+ return nil, fmt.Errorf("could not get project from subdomain %s: %w", subdomain, err)
7 }
8
9 // get user ID
10 user, err := dbpool.FindUserForName(props.Username)
11 if err != nil {
12- return nil, err
13+ return nil, fmt.Errorf("could not find user for name %s: %w", props.Username, err)
14 }
15
16 projectID := ""
17@@ -641,7 +641,12 @@ func deserializeCaddyAccessLog(dbpool db.DB, access *AccessLog) (*db.AnalyticsVi
18 if space == "pgs" { // figure out project ID
19 project, err := dbpool.FindProjectByName(user.ID, props.ProjectName)
20 if err != nil {
21- return nil, err
22+ return nil, fmt.Errorf(
23+ "could not find project by name, (user:%s, project:%s): %w",
24+ user.ID,
25+ props.ProjectName,
26+ err,
27+ )
28 }
29 projectID = project.ID
30 } else if space == "prose" { // figure out post ID
31@@ -651,7 +656,13 @@ func deserializeCaddyAccessLog(dbpool db.DB, access *AccessLog) (*db.AnalyticsVi
32 cleanPath := strings.TrimPrefix(path, "/")
33 post, err := dbpool.FindPostWithSlug(cleanPath, user.ID, space)
34 if err != nil {
35- return nil, err
36+ return nil, fmt.Errorf(
37+ "could not find post with slug (path:%s, userId:%s, space:%s): %w",
38+ cleanPath,
39+ user.ID,
40+ space,
41+ err,
42+ )
43 }
44 postID = post.ID
45 }
46@@ -676,7 +687,7 @@ func accessLogToVisit(dbpool db.DB, line string) (*db.AnalyticsVisits, error) {
47 accessLog := AccessLog{}
48 err := json.Unmarshal([]byte(line), &accessLog)
49 if err != nil {
50- return nil, err
51+ return nil, fmt.Errorf("could not unmarshal line: %w", err)
52 }
53
54 return deserializeCaddyAccessLog(dbpool, &accessLog)