- commit
- 9e30a1b
- parent
- 485c1f5
- author
- Eric Bower
- date
- 2024-04-04 16:10:45 +0000 UTC
chore(pgs): add better err messages
1 files changed,
+26,
-13
+26,
-13
1@@ -51,14 +51,18 @@ func checkHandler(w http.ResponseWriter, r *http.Request) {
2 subdomain := shared.GetCustomDomain(hostDomain, cfg.Space)
3 props, err := getProjectFromSubdomain(subdomain)
4 if err != nil {
5- logger.Error(err.Error())
6+ logger.Error(
7+ "could not get project from subdomain",
8+ "subdomain", subdomain,
9+ "err", err.Error(),
10+ )
11 w.WriteHeader(http.StatusNotFound)
12 return
13 }
14
15 u, err := dbpool.FindUserForName(props.Username)
16 if err != nil {
17- logger.Error(err.Error())
18+ logger.Error("could not find user", "err", err.Error())
19 w.WriteHeader(http.StatusNotFound)
20 return
21 }
22@@ -69,7 +73,12 @@ func checkHandler(w http.ResponseWriter, r *http.Request) {
23 )
24 p, err := dbpool.FindProjectByName(u.ID, props.ProjectName)
25 if err != nil {
26- logger.Error(err.Error())
27+ logger.Error(
28+ "could not find project for user",
29+ "user", u.Name,
30+ "project", props.ProjectName,
31+ "err", err.Error(),
32+ )
33 w.WriteHeader(http.StatusNotFound)
34 return
35 }
36@@ -96,7 +105,7 @@ func createRssHandler(by string) http.HandlerFunc {
37
38 pager, err := dbpool.FindAllProjects(&db.Pager{Num: 100, Page: 0}, by)
39 if err != nil {
40- logger.Error(err.Error())
41+ logger.Error("could not find projects", "err", err.Error())
42 http.Error(w, err.Error(), http.StatusInternalServerError)
43 return
44 }
45@@ -140,14 +149,14 @@ func createRssHandler(by string) http.HandlerFunc {
46
47 rss, err := feed.ToAtom()
48 if err != nil {
49- logger.Error(err.Error())
50+ logger.Error("could not convert feed to atom", "err", err.Error())
51 http.Error(w, "Could not generate atom rss feed", http.StatusInternalServerError)
52 }
53
54 w.Header().Add("Content-Type", "application/atom+xml")
55 _, err = w.Write([]byte(rss))
56 if err != nil {
57- logger.Error(err.Error())
58+ logger.Error("http write failed", "err", err.Error())
59 }
60 }
61 }
62@@ -165,14 +174,14 @@ func (h *AssetHandler) handle(w http.ResponseWriter, r *http.Request) {
63 buf := new(strings.Builder)
64 _, err := io.Copy(buf, redirectFp)
65 if err != nil {
66- h.Logger.Error(err.Error())
67+ h.Logger.Error("io copy", "err", err.Error())
68 http.Error(w, "cannot read _redirects file", http.StatusInternalServerError)
69 return
70 }
71
72 redirects, err = parseRedirectText(buf.String())
73 if err != nil {
74- h.Logger.Error(err.Error())
75+ h.Logger.Error("could not parse redirect text", "err", err.Error())
76 }
77 }
78
79@@ -260,14 +269,14 @@ func (h *AssetHandler) handle(w http.ResponseWriter, r *http.Request) {
80 buf := new(strings.Builder)
81 _, err := io.Copy(buf, headersFp)
82 if err != nil {
83- h.Logger.Error(err.Error())
84+ h.Logger.Error("io copy", "err", err.Error())
85 http.Error(w, "cannot read _headers file", http.StatusInternalServerError)
86 return
87 }
88
89 headers, err = parseHeaderText(buf.String())
90 if err != nil {
91- h.Logger.Error(err.Error())
92+ h.Logger.Error("could not parse header text", "err", err.Error())
93 }
94 }
95
96@@ -424,7 +433,7 @@ func ImgAssetRequest(hasPerm HasPerm) http.HandlerFunc {
97 opts, err := storage.UriToImgProcessOpts(imgOpts)
98 if err != nil {
99 errMsg := fmt.Sprintf("error processing img options: %s", err.Error())
100- logger.Info(errMsg)
101+ logger.Error("error processing img options", "err", errMsg)
102 http.Error(w, errMsg, http.StatusUnprocessableEntity)
103 }
104
105@@ -485,7 +494,7 @@ func StartApiServer() {
106 }
107
108 if err != nil {
109- logger.Error(err.Error())
110+ logger.Error("could not connect to minio", "err", err.Error())
111 return
112 }
113
114@@ -507,5 +516,9 @@ func StartApiServer() {
115 "domain", cfg.Domain,
116 "email", cfg.Email,
117 )
118- logger.Error(http.ListenAndServe(portStr, router).Error())
119+ err = http.ListenAndServe(portStr, router)
120+ logger.Error(
121+ "listen and serve",
122+ "err", err.Error(),
123+ )
124 }