10000 chore: More UI friendly errors by Emyrk · Pull Request #1994 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: More UI friendly errors #1994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix proper captalization
  • Loading branch information
Emyrk committed Jun 3, 2022
commit a8e78bbe7df4adffa2440bd4ec87561d1004b0ba
8 changes: 4 additions & 4 deletions coderd/httpmw/apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: "Api key is invalid",
Message: "API key is invalid",
})
return
}
Expand All @@ -111,7 +111,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
// Checking to see if the secret is valid.
if subtle.ConstantTimeCompare(key.HashedSecret, hashed[:]) != 1 {
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: "Api key secret is invalid",
Message: "API key secret is invalid",
})
return
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
// Checking if the key is expired.
if key.ExpiresAt.Before(now) {
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
Message: fmt.Sprintf("Api key expired at %q", key.ExpiresAt.String()),
Message: fmt.Sprintf("API key expired at %q", key.ExpiresAt.String()),
})
return
}
Expand Down Expand Up @@ -184,7 +184,7 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
})
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("Api key couldn't update: %s", err.Error()),
Message: fmt.Sprintf("API key couldn't update: %s", err.Error()),
})
return
}
Expand Down
2 changes: 1 addition & 1 deletion coderd/httpmw/httpmw.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func parseUUID(rw http.ResponseWriter, r *http.Request, param string) (uuid.UUID
parsed, err := uuid.Parse(rawID)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("Invalid uuid %q", param),
Message: fmt.Sprintf("Invalid UUID %q", param),
Detail: err.Error(),
})
return uuid.UUID{}, false
Expand Down
2 changes: 1 addition & 1 deletion coderd/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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: "Query param 'after_id' must be a valid uuid",
Message: "Query param 'after_id' must be a valid UUID",
Detail: err.Error(),
Validations: []httpapi.Error{
{Field: "after_id", Detail: err.Error()},
Expand Down
4 changes: 2 additions & 2 deletions coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ func readScopeAndID(rw http.ResponseWriter, r *http.Request) (database.Parameter
uid, err := uuid.Parse(id)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("Invalid uuid %q", id),
Message: fmt.Sprintf("Invalid UUID %q", id),
Detail: err.Error(),
Validations: []httpapi.Error{
{Field: "id", Detail: "Invalid uuid"},
{Field: "id", Detail: "Invalid UUID"},
},
})
return scope, uuid.Nil, false
Expand Down
4 changes: 2 additions & 2 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
reconnect, err := uuid.Parse(r.URL.Query().Get("reconnect"))
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "Query param 'reconnect' must be a valid uuid",
Message: "Query param 'reconnect' must be a valid UUID",
Detail: err.Error(),
Validations: []httpapi.Error{
{Field: "reconnect", Detail: "invalid uuid"},
{Field: "reconnect", Detail: "invalid UUID"},
},
})
return
Expand Down
14 changes: 7 additions & 7 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
orgID, err := uuid.Parse(orgFilter)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "Query param \"organization_id\" must be a valid uuid",
Message: "Query param \"organization_id\" must be a valid UUID",
Detail: err.Error(),
Validations: []httpapi.Error{
{Field: "organization_id", Detail: "Must be a valid uuid"},
{Field: "organization_id", Detail: "Must be a valid UUID"},
},
})
return
Expand All @@ -173,10 +173,10 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
})
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "Query param \"owner\" must be a valid uuid or username",
Message: "Query param \"owner\" must be a valid UUID or username",
Detail: err.Error(),
Validations: []httpapi.Error{
{Field: "owner", Detail: "Must be a valid uuid or username"},
{Field: "owner", Detail: "Must be a valid UUID or username"},
},
})
return
Expand Down Expand Up @@ -375,7 +375,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
dbTTL, err := validWorkspaceTTLMillis(createWorkspace.TTLMillis)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "Invalid workspace ttl",
Message: "Invalid workspace TTL",
Detail: err.Error(),
Validations: []httpapi.Error{
{
Expand Down Expand Up @@ -598,7 +598,7 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
dbTTL, err := validWorkspaceTTLMillis(req.TTLMillis)
if err != nil {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "Invalid workspace ttl",
Message: "Invalid workspace TTL",
Detail: err.Error(),
Validations: []httpapi.Error{
{
Expand All @@ -616,7 +616,7 @@ func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
})
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: "Detail error updating workspace ttl",
Message: "Detail error updating workspace TTL",
Detail: err.Error(),
})
return
Expand Down
0