@@ -65,15 +65,15 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
65
65
}
66
66
if cookieValue == "" {
67
67
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 ),
69
69
})
70
70
return
71
71
}
72
72
parts := strings .Split (cookieValue , "-" )
73
73
// APIKeys are formatted: ID-SECRET
74
74
if len (parts ) != 2 {
75
75
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 ),
77
77
})
78
78
return
79
79
}
@@ -82,26 +82,27 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
82
82
// Ensuring key lengths are valid.
83
83
if len (keyID ) != 10 {
84
84
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 ),
86
86
})
87
87
return
88
88
}
89
89
if len (keySecret ) != 22 {
90
90
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 ),
92
92
})
93
93
return
94
94
}
95
95
key , err := db .GetAPIKeyByID (r .Context (), keyID )
96
96
if err != nil {
97
97
if errors .Is (err , sql .ErrNoRows ) {
98
98
httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
99
- Message : "api key is invalid" ,
99
+ Message : "API key is invalid" ,
100
100
})
101
101
return
102
102
}
103
103
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 (),
105
106
})
106
107
return
107
108
}
@@ -110,7 +111,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
110
111
// Checking to see if the secret is valid.
111
112
if subtle .ConstantTimeCompare (key .HashedSecret , hashed [:]) != 1 {
112
113
httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
113
- Message : "api key secret is invalid" ,
114
+ Message : "API key secret is invalid" ,
114
115
})
115
116
return
116
117
}
@@ -127,7 +128,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
127
128
oauthConfig = oauth .Github
128
129
default :
129
130
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 ),
131
132
})
132
133
return
133
134
}
@@ -139,7 +140,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
139
140
}).Token ()
140
141
if err != nil {
141
142
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 (),
143
145
})
144
146
return
145
147
}
@@ -154,7 +156,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
154
156
// Checking if the key is expired.
155
157
if key .ExpiresAt .Before (now ) {
156
158
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 ()),
158
160
})
159
161
return
160
162
}
@@ -182,7 +184,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
182
184
})
183
185
if err != nil {
184
186
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 ()),
186
188
})
187
189
return
188
190
}
@@ -194,14 +196,15 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
194
196
roles , err := db .GetAuthorizationUserRoles (r .Context (), key .UserID )
195
197
if err != nil {
196
198
httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
197
- Message : "roles not found" ,
199
+ Message : "Internal error fetching user's roles" ,
200
+ Detail : err .Error (),
198
201
})
199
202
return
200
203
}
201
204
202
205
if roles .Status != database .UserStatusActive {
203
206
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 ),
205
208
})
206
209
return
207
210
}
0 commit comments