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

Commitdfac9a2

Browse files
presleypkylecarbs
authored andcommitted
refactor: rename errors to validations (#2105)
* Update validation error unpacking* Rename validations on backend* Format
1 parent7a25393 commitdfac9a2

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

‎coderd/httpapi/httpapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Response struct {
6767
// Validations are form field-specific friendly error messages. They will be
6868
// shown on a form field in the UI. These can also be used to add additional
6969
// context if there is a set of errors in the primary 'Message'.
70-
Validations []Error`json:"errors,omitempty"`
70+
Validations []Error`json:"validations,omitempty"`
7171
}
7272

7373
// Error represents a scoped error to a user input.

‎site/src/api/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("mapApiErrorToFieldErrors", () => {
2929
expect(
3030
mapApiErrorToFieldErrors({
3131
message:"Invalid entry",
32-
errors:[{detail:"Username is already in use",field:"username"}],
32+
validations:[{detail:"Username is already in use",field:"username"}],
3333
}),
3434
).toEqual({
3535
username:"Username is already in use",

‎site/src/api/errors.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export type FieldErrors = Record<FieldError["field"], FieldError["detail"]>
1515

1616
exportinterfaceApiErrorResponse{
1717
message:string
18-
errors?:FieldError[]
18+
detail?:string
19+
validations?:FieldError[]
1920
}
2021

2122
exporttypeApiError=AxiosError<ApiErrorResponse>&{response:AxiosResponse<ApiErrorResponse>}
@@ -39,13 +40,13 @@ export const isApiError = (err: any): err is ApiError => {
3940
*@param error ApiError
4041
*@returns true if the ApiError contains error messages for specific form fields.
4142
*/
42-
exportconsthasApiFieldErrors=(error:ApiError):boolean=>Array.isArray(error.response.data.errors)
43+
exportconsthasApiFieldErrors=(error:ApiError):boolean=>Array.isArray(error.response.data.validations)
4344

4445
exportconstmapApiErrorToFieldErrors=(apiErrorResponse:ApiErrorResponse):FieldErrors=>{
4546
constresult:FieldErrors={}
4647

47-
if(apiErrorResponse.errors){
48-
for(consterrorofapiErrorResponse.errors){
48+
if(apiErrorResponse.validations){
49+
for(consterrorofapiErrorResponse.validations){
4950
result[error.field]=error.detail||Language.errorsByCode.defaultErrorCode
5051
}
5152
}

‎site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ describe("AccountPage", () => {
5454
jest.spyOn(API,"updateProfile").mockRejectedValueOnce({
5555
isAxiosError:true,
5656
response:{
57-
data:{message:"Invalid profile",errors:[{detail:"Username is already in use",field:"username"}]},
57+
data:{
58+
message:"Invalid profile",
59+
validations:[{detail:"Username is already in use",field:"username"}],
60+
},
5861
},
5962
})
6063

‎site/src/pages/UserSettingsPage/SecurityPage/SecurityPage.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ describe("SecurityPage", () => {
4949
jest.spyOn(API,"updateUserPassword").mockRejectedValueOnce({
5050
isAxiosError:true,
5151
response:{
52-
data:{message:"Incorrect password.",errors:[{detail:"Incorrect password.",field:"old_password"}]},
52+
data:{
53+
message:"Incorrect password.",
54+
validations:[{detail:"Incorrect password.",field:"old_password"}],
55+
},
5356
},
5457
})
5558

@@ -68,7 +71,7 @@ describe("SecurityPage", () => {
6871
jest.spyOn(API,"updateUserPassword").mockRejectedValueOnce({
6972
isAxiosError:true,
7073
response:{
71-
data:{message:"Invalid password.",errors:[{detail:"Invalid password.",field:"password"}]},
74+
data:{message:"Invalid password.",validations:[{detail:"Invalid password.",field:"password"}]},
7275
},
7376
})
7477

‎site/src/pages/UsersPage/CreateUserPage/CreateUserPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("Create User Page", () => {
5858
ctx.status(400),
5959
ctx.json({
6060
message:"invalid field",
61-
errors:[
61+
validations:[
6262
{
6363
detail:fieldErrorMessage,
6464
field:"username",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp