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

refactor: replace Code by Detail in the http API error#1011

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 5 commits intomainfrombq/1008/replace-code-by-detail
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
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
8 changes: 4 additions & 4 deletionscoderd/httpapi/httpapi.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,8 +58,8 @@ type Response struct {

// Error represents a scoped error to a user input.
type Error struct {
Field string `json:"field" validate:"required"`
Codestring `json:"code" validate:"required"`
Fieldstring `json:"field" validate:"required"`
Detailstring `json:"detail" validate:"required"`
}

// Write outputs a standardized format to an HTTP response body.
Expand DownExpand Up@@ -97,8 +97,8 @@ func Read(rw http.ResponseWriter, r *http.Request, value interface{}) bool {
apiErrors := make([]Error, 0, len(validationErrors))
for _, validationError := range validationErrors {
apiErrors = append(apiErrors, Error{
Field: validationError.Field(),
Code: validationError.Tag(),
Field:validationError.Field(),
Detail: validationError.Tag(),
})
}
Write(rw, http.StatusBadRequest, Response{
Expand Down
2 changes: 1 addition & 1 deletioncoderd/httpapi/httpapi_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,7 +76,7 @@ func TestRead(t *testing.T) {
require.NoError(t, err)
require.Len(t, v.Errors, 1)
require.Equal(t, v.Errors[0].Field, "value")
require.Equal(t, v.Errors[0].Code, "required")
require.Equal(t, v.Errors[0].Detail, "required")
})
}

Expand Down
4 changes: 2 additions & 2 deletionscoderd/organizations.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -162,8 +162,8 @@ func (api *api) postTemplatesByOrganization(rw http.ResponseWriter, r *http.Requ
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
Message: fmt.Sprintf("template %q already exists", createTemplate.Name),
Errors: []httpapi.Error{{
Field: "name",
Code: "exists",
Field:"name",
Detail: "this value is already in use and should be unique",
}},
})
return
Expand Down
16 changes: 8 additions & 8 deletionscoderd/users.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -289,14 +289,14 @@ func (api *api) putUserProfile(rw http.ResponseWriter, r *http.Request) {
responseErrors := []httpapi.Error{}
if existentUser.Email == params.Email {
responseErrors = append(responseErrors, httpapi.Error{
Field: "email",
Code: "exists",
Field:"email",
Detail: "this value is already in use and should be unique",
})
}
if existentUser.Username == params.Username {
responseErrors = append(responseErrors, httpapi.Error{
Field: "username",
Code: "exists",
Field:"username",
Detail: "this value is already in use and should be unique",
})
}
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
Expand DownExpand Up@@ -591,8 +591,8 @@ func (api *api) postWorkspacesByUser(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: fmt.Sprintf("template %q doesn't exist", createWorkspace.TemplateID.String()),
Errors: []httpapi.Error{{
Field: "template_id",
Code: "not_found",
Field:"template_id",
Detail: "template not found",
}},
})
return
Expand DownExpand Up@@ -637,8 +637,8 @@ func (api *api) postWorkspacesByUser(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
Message: fmt.Sprintf("workspace %q already exists in the %q template", createWorkspace.Name, template.Name),
Errors: []httpapi.Error{{
Field: "name",
Code: "exists",
Field:"name",
Detail: "this value is already in use and should be unique",
}},
})
return
Expand Down
4 changes: 2 additions & 2 deletionscoderd/workspaces.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -115,8 +115,8 @@ func (api *api) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
Message: "template version not found",
Errors: []httpapi.Error{{
Field: "template_version_id",
Code: "exists",
Field:"template_version_id",
Detail: "template version not found",
}},
})
return
Expand Down
2 changes: 1 addition & 1 deletioncodersdk/client.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -127,7 +127,7 @@ func (e *Error) Error() string {
var builder strings.Builder
_, _ = fmt.Fprintf(&builder, "status code %d: %s", e.statusCode, e.Message)
for _, err := range e.Errors {
_, _ = fmt.Fprintf(&builder, "\n\t%s: %s", err.Field, err.Code)
_, _ = fmt.Fprintf(&builder, "\n\t%s: %s", err.Field, err.Detail)
}
return builder.String()
}

[8]ページ先頭

©2009-2025 Movatter.jp