Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3311c2f

Browse files
refactor: replace Code by Detail in the http API error (#1011)
1 parent9faa39a commit3311c2f

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
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
typeErrorstruct {
61-
Fieldstring`json:"field" validate:"required"`
62-
Codestring`json:"code" validate:"required"`
61+
Fieldstring`json:"field" validate:"required"`
62+
Detailstring`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:=rangevalidationErrors {
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/httpapi/httpapi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestRead(t *testing.T) {
7676
require.NoError(t,err)
7777
require.Len(t,v.Errors,1)
7878
require.Equal(t,v.Errors[0].Field,"value")
79-
require.Equal(t,v.Errors[0].Code,"required")
79+
require.Equal(t,v.Errors[0].Detail,"required")
8080
})
8181
}
8282

‎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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ func (api *api) putUserProfile(rw http.ResponseWriter, r *http.Request) {
289289
responseErrors:= []httpapi.Error{}
290290
ifexistentUser.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
ifexistentUser.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

‎codersdk/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (e *Error) Error() string {
127127
varbuilder strings.Builder
128128
_,_=fmt.Fprintf(&builder,"status code %d: %s",e.statusCode,e.Message)
129129
for_,err:=rangee.Errors {
130-
_,_=fmt.Fprintf(&builder,"\n\t%s: %s",err.Field,err.Code)
130+
_,_=fmt.Fprintf(&builder,"\n\t%s: %s",err.Field,err.Detail)
131131
}
132132
returnbuilder.String()
133133
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp