Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49f0ffe

Browse files
committed
refactor: replace Code by Detail in the http API error
1 parent 76f8ff9 commit 49f0ffe

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

coderd/httpapi/httpapi.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ type Response struct {
5858

5959
// Error represents a scoped error to a user input.
6060
type Error struct {
61-
Field string `json:"field" validate:"required"`
62-
Code string `json:"code" validate:"required"`
61+
Field string `json:"field" validate:"required"`
62+
Detail string `json:"detail" validate:"required"`
6363
}
6464

6565
// Write outputs a standardized format to an HTTP response body.
@@ -97,8 +97,8 @@ func Read(rw http.ResponseWriter, r *http.Request, value interface{}) bool {
9797
apiErrors := make([]Error, 0, len(validationErrors))
9898
for _, validationError := range validationErrors {
9999
apiErrors = append(apiErrors, Error{
100-
Field: validationError.Field(),
101-
Code: validationError.Tag(),
100+
Field: validationError.Field(),
101+
Detail: validationError.Tag(),
102102
})
103103
}
104104
Write(rw, http.StatusBadRequest, Response{

coderd/organizations.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ func (api *api) postTemplatesByOrganization(rw http.ResponseWriter, r *http.Requ
162162
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
163163
Message: fmt.Sprintf("template %q already exists", createTemplate.Name),
164164
Errors: []httpapi.Error{{
165-
Field: "name",
166-
Code: "exists",
165+
Field: "name",
166+
Detail: "this value is already in use and should be unique",
167167
}},
168168
})
169169
return

coderd/users.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (api *api) firstUser(rw http.ResponseWriter, r *http.Request) {
4545
})
4646
}
4747

48-
// Creates the initial user for a Coder deployment.
48+
// Creates the initial user for a Detailr deployment.
4949
func (api *api) postFirstUser(rw http.ResponseWriter, r *http.Request) {
5050
var createUser codersdk.CreateFirstUserRequest
5151
if !httpapi.Read(rw, r, &createUser) {
@@ -289,14 +289,14 @@ func (api *api) putUserProfile(rw http.ResponseWriter, r *http.Request) {
289289
responseErrors := []httpapi.Error{}
290290
if existentUser.Email == params.Email {
291291
responseErrors = append(responseErrors, httpapi.Error{
292-
Field: "email",
293-
Code: "exists",
292+
Field: "email",
293+
Detail: "this value is already in use and should be unique",
294294
})
295295
}
296296
if existentUser.Username == params.Username {
297297
responseErrors = append(responseErrors, httpapi.Error{
298-
Field: "username",
299-
Code: "exists",
298+
Field: "username",
299+
Detail: "this value is already in use and should be unique",
300300
})
301301
}
302302
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
@@ -591,8 +591,8 @@ func (api *api) postWorkspacesByUser(rw http.ResponseWriter, r *http.Request) {
591591
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
592592
Message: fmt.Sprintf("template %q doesn't exist", createWorkspace.TemplateID.String()),
593593
Errors: []httpapi.Error{{
594-
Field: "template_id",
595-
Code: "not_found",
594+
Field: "template_id",
595+
Detail: "template not found",
596596
}},
597597
})
598598
return
@@ -637,8 +637,8 @@ func (api *api) postWorkspacesByUser(rw http.ResponseWriter, r *http.Request) {
637637
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
638638
Message: fmt.Sprintf("workspace %q already exists in the %q template", createWorkspace.Name, template.Name),
639639
Errors: []httpapi.Error{{
640-
Field: "name",
641-
Code: "exists",
640+
Field: "name",
641+
Detail: "this value is already in use and should be unique",
642642
}},
643643
})
644644
return

coderd/workspaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func (api *api) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
115115
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
116116
Message: "template version not found",
117117
Errors: []httpapi.Error{{
118-
Field: "template_version_id",
119-
Code: "exists",
118+
Field: "template_version_id",
119+
Detail: "template version not found",
120120
}},
121121
})
122122
return

0 commit comments

Comments
 (0)