@@ -14,6 +14,13 @@ import (
14
14
15
15
type userParamContextKey struct {}
16
16
17
+ const (
18
+ // userErrorMessage is a constant so that no information about the state
19
+ // of the queried user can be gained. We return the same error if the user
20
+ // does not exist, or if the input is just garbage.
21
+ userErrorMessage = "\" user\" must be an existing uuid or username"
22
+ )
23
+
17
24
// UserParam returns the user from the ExtractUserParam handler.
18
25
func UserParam (r * http.Request ) database.User {
19
26
user , ok := r .Context ().Value (userParamContextKey {}).(database.User )
@@ -51,8 +58,8 @@ func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
51
58
// If the userQuery is a valid uuid
52
59
user , err = db .GetUserByID (r .Context (), userID )
53
60
if err != nil {
54
- httpapi .Write (rw , http .StatusInternalServerError , httpapi.Response {
55
- Message : fmt . Sprintf ( "get user: %s" , err . Error ()) ,
61
+ httpapi .Write (rw , http .StatusBadRequest , httpapi.Response {
62
+ Message : userErrorMessage ,
56
63
})
57
64
return
58
65
}
@@ -62,12 +69,8 @@ func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
62
69
Username : userQuery ,
63
70
})
64
71
if err != nil {
65
- // If the error is no rows, they might have inputted something
66
- // that is not a username or uuid. Regardless, let's not indicate if
67
- // the user exists or not. Just lump all these errors into
68
- // something generic.
69
72
httpapi .Write (rw , http .StatusBadRequest , httpapi.Response {
70
- Message : " \" user \" must be a uuid or username" ,
73
+ Message : userErrorMessage ,
71
74
})
72
75
return
73
76
}
0 commit comments