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

This commit is contained in:
Bruno Quaresma
2022-04-18 11:02:54 -05:00
committed by GitHub
parent 9faa39aa23
commit 3311c2f65d
6 changed files with 18 additions and 18 deletions

View File

@ -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{
@ -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
@ -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