chore: Update BE http errors to be ui friendly (#1994)

* chore: More UI friendly errors

Mainly capitlization + messages prefix error
This commit is contained in:
Steven Masley
2022-06-03 21:48:09 +00:00
committed by GitHub
parent 847e2b18da
commit c9a4642a12
42 changed files with 544 additions and 317 deletions
+12 -4
View File
@@ -1,7 +1,6 @@
package coderd
import (
"fmt"
"net/http"
"strconv"
@@ -25,7 +24,10 @@ func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Paginat
afterID, err = uuid.Parse(r.URL.Query().Get("after_id"))
if err != nil {
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("after_id must be a valid uuid: %s", err.Error()),
Message: "Query param 'after_id' must be a valid UUID",
Validations: []httpapi.Error{
{Field: "after_id", Detail: err.Error()},
},
})
return p, false
}
@@ -34,7 +36,10 @@ func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Paginat
limit, err = strconv.Atoi(s)
if err != nil {
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("limit must be an integer: %s", err.Error()),
Message: "Query param 'limit' must be a valid integer",
Validations: []httpapi.Error{
{Field: "limit", Detail: err.Error()},
},
})
return p, false
}
@@ -43,7 +48,10 @@ func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Paginat
offset, err = strconv.Atoi(s)
if err != nil {
httpapi.Write(w, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("offset must be an integer: %s", err.Error()),
Message: "Query param 'offset' must be a valid integer",
Validations: []httpapi.Error{
{Field: "offset", Detail: err.Error()},
},
})
return p, false
}