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 16:48:09 -05:00
committed by GitHub
parent 847e2b18da
commit c9a4642a12
42 changed files with 544 additions and 317 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"net/http"
"github.com/go-chi/chi/v5"
@ -35,13 +34,14 @@ func ExtractWorkspaceResourceParam(db database.Store) func(http.Handler) http.Ha
resource, err := db.GetWorkspaceResourceByID(r.Context(), resourceUUID)
if errors.Is(err, sql.ErrNoRows) {
httpapi.Write(rw, http.StatusNotFound, httpapi.Response{
Message: "resource doesn't exist with that id",
Message: "Resource doesn't exist with that id",
})
return
}
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get provisioner resource: %s", err),
Message: "Internal error fetching provisioner resource",
Detail: err.Error(),
})
return
}
@ -49,7 +49,8 @@ func ExtractWorkspaceResourceParam(db database.Store) func(http.Handler) http.Ha
job, err := db.GetProvisionerJobByID(r.Context(), resource.JobID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get provisioner job: %s", err),
Message: "Internal error provisioner job",
Detail: err.Error(),
})
return
}
@ -62,7 +63,8 @@ func ExtractWorkspaceResourceParam(db database.Store) func(http.Handler) http.Ha
build, err := db.GetWorkspaceBuildByJobID(r.Context(), job.ID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Message: fmt.Sprintf("get workspace build: %s", err),
Message: "Internal error workspace build",
Detail: err.Error(),
})
return
}