@@ -65,15 +65,15 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
6565 }
6666 if cookieValue == "" {
6767 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
68- Message : fmt .Sprintf ("%q cookie or query parameter must be provided" , SessionTokenKey ),
68+ Message : fmt .Sprintf ("Cookie %q or query parameter must be provided" , SessionTokenKey ),
6969 })
7070 return
7171 }
7272 parts := strings .Split (cookieValue , "-" )
7373 // APIKeys are formatted: ID-SECRET
7474 if len (parts ) != 2 {
7575 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
76- Message : fmt .Sprintf ("invalid %q cookie api key format" , SessionTokenKey ),
76+ Message : fmt .Sprintf ("Invalid %q cookie API key format" , SessionTokenKey ),
7777 })
7878 return
7979 }
@@ -82,26 +82,27 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
8282 // Ensuring key lengths are valid.
8383 if len (keyID ) != 10 {
8484 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
85- Message : fmt .Sprintf ("invalid %q cookie api key id" , SessionTokenKey ),
85+ Message : fmt .Sprintf ("Invalid %q cookie API key id" , SessionTokenKey ),
8686 })
8787 return
8888 }
8989 if len (keySecret ) != 22 {
9090 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
91- Message : fmt .Sprintf ("invalid %q cookie api key secret" , SessionTokenKey ),
91+ Message : fmt .Sprintf ("Invalid %q cookie API key secret" , SessionTokenKey ),
9292 })
9393 return
9494 }
9595 key , err := db .GetAPIKeyByID (r .Context (), keyID )
9696 if err != nil {
9797 if errors .Is (err , sql .ErrNoRows ) {
9898 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
99- Message : "api key is invalid" ,
99+ Message : "API key is invalid" ,
100100 })
101101 return
102102 }
103103 httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
104- Message : fmt .Sprintf ("get api key by id: %s" , err .Error ()),
104+ Message : "Internal error fetching API key by id" ,
105+ Detail : err .Error (),
105106 })
106107 return
107108 }
@@ -110,7 +111,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
110111 // Checking to see if the secret is valid.
111112 if subtle .ConstantTimeCompare (key .HashedSecret , hashed [:]) != 1 {
112113 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
113- Message : "api key secret is invalid" ,
114+ Message : "API key secret is invalid" ,
114115 })
115116 return
116117 }
@@ -127,7 +128,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
127128 oauthConfig = oauth .Github
128129 default :
129130 httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
130- Message : fmt .Sprintf ("unexpected authentication type %q" , key .LoginType ),
131+ Message : fmt .Sprintf ("Unexpected authentication type %q" , key .LoginType ),
131132 })
132133 return
133134 }
@@ -139,7 +140,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
139140 }).Token ()
140141 if err != nil {
141142 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
142- Message : fmt .Sprintf ("couldn't refresh expired oauth token: %s" , err .Error ()),
143+ Message : "Could not refresh expired Oauth token" ,
144+ Detail : err .Error (),
143145 })
144146 return
145147 }
@@ -154,7 +156,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
154156 // Checking if the key is expired.
155157 if key .ExpiresAt .Before (now ) {
156158 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
157- Message : fmt .Sprintf ("api key expired at %q" , key .ExpiresAt .String ()),
159+ Message : fmt .Sprintf ("API key expired at %q" , key .ExpiresAt .String ()),
158160 })
159161 return
160162 }
@@ -182,7 +184,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
182184 })
183185 if err != nil {
184186 httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
185- Message : fmt .Sprintf ("api key couldn't update: %s" , err .Error ()),
187+ Message : fmt .Sprintf ("API key couldn't update: %s" , err .Error ()),
186188 })
187189 return
188190 }
@@ -194,14 +196,15 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
194196 roles , err := db .GetAuthorizationUserRoles (r .Context (), key .UserID )
195197 if err != nil {
196198 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
197- Message : "roles not found" ,
199+ Message : "Internal error fetching user's roles" ,
200+ Detail : err .Error (),
198201 })
199202 return
200203 }
201204
202205 if roles .Status != database .UserStatusActive {
203206 httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
204- Message : fmt .Sprintf ("user is not active (status = %q), contact an admin to reactivate your account" , roles .Status ),
207+ Message : fmt .Sprintf ("User is not active (status = %q). Contact an admin to reactivate your account. " , roles .Status ),
205208 })
206209 return
207210 }
0 commit comments