chore: Linter rule for properly formatted api errors (#2123)

* chore: Linter rule for properly formatted api errors
* Add omitempty to 'Detail' field
This commit is contained in:
Steven Masley
2022-06-07 14:33:06 +00:00
committed by GitHub
parent 3f1e885d21
commit af401e3fe1
37 changed files with 351 additions and 302 deletions
+3 -3
View File
@@ -17,7 +17,7 @@ const (
// userErrorMessage is a constant so that no information about the state
// of the queried user can be gained. We return the same error if the user
// does not exist, or if the input is just garbage.
userErrorMessage = "\"user\" must be an existing uuid or username"
userErrorMessage = "\"user\" must be an existing uuid or username."
)
// UserParam returns the user from the ExtractUserParam handler.
@@ -40,7 +40,7 @@ func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
userQuery := chi.URLParam(r, "user")
if userQuery == "" {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "\"user\" must be provided",
Message: "\"user\" must be provided.",
})
return
}
@@ -49,7 +49,7 @@ func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
user, err = db.GetUserByID(r.Context(), APIKey(r).UserID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: "Internal error fetching user",
Message: "Internal error fetching user.",
Detail: err.Error(),
})
return