Skip to content

Commit 16cf5af

Browse files
committed
Fix validation error API response
1 parent fc894ab commit 16cf5af

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/api/components/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function getCorrectJsonSchema<T, U>({
6161
export const notAuthenticatedError = getCorrectJsonSchema({
6262
schema: z
6363
.object({
64+
error: z.literal(true),
6465
name: z.literal("UnauthenticatedError"),
6566
id: z.literal(102),
6667
message: z.string().min(1),
@@ -70,6 +71,7 @@ export const notAuthenticatedError = getCorrectJsonSchema({
7071
}),
7172
description: "The request could not be authenticated.",
7273
example: {
74+
error: true,
7375
name: "UnauthenticatedError",
7476
id: 102,
7577
message: "Token not found.",
@@ -79,6 +81,7 @@ export const notAuthenticatedError = getCorrectJsonSchema({
7981
export const notFoundError = getCorrectJsonSchema({
8082
schema: z
8183
.object({
84+
error: z.literal(true),
8285
name: z.literal("NotFoundError"),
8386
id: z.literal(103),
8487
message: z.string().min(1),
@@ -88,6 +91,7 @@ export const notFoundError = getCorrectJsonSchema({
8891
}),
8992
description: "The resource could not be found.",
9093
example: {
94+
error: true,
9195
name: "NotFoundError",
9296
id: 103,
9397
message: "{url} is not a valid URL.",
@@ -97,6 +101,7 @@ export const notFoundError = getCorrectJsonSchema({
97101
export const notAuthorizedError = getCorrectJsonSchema({
98102
schema: z
99103
.object({
104+
error: z.literal(true),
100105
name: z.literal("UnauthorizedError"),
101106
id: z.literal(101),
102107
message: z.string().min(1),
@@ -107,6 +112,7 @@ export const notAuthorizedError = getCorrectJsonSchema({
107112
description:
108113
"The caller does not have the appropriate permissions for this task.",
109114
example: {
115+
error: true,
110116
name: "UnauthorizedError",
111117
id: 101,
112118
message: "User does not have the privileges for this task.",
@@ -119,6 +125,7 @@ export const internalServerError = getCorrectJsonSchema({
119125
"application/json": {
120126
schema: z
121127
.object({
128+
error: z.literal(true),
122129
name: z.literal("InternalServerError"),
123130
id: z.literal(100),
124131
message: z.string().min(1),
@@ -133,6 +140,7 @@ export const internalServerError = getCorrectJsonSchema({
133140
},
134141
description: "The server encountered an error processing the request.",
135142
example: {
143+
error: true,
136144
name: "InternalServerError",
137145
id: 100,
138146
message:
@@ -143,6 +151,7 @@ export const internalServerError = getCorrectJsonSchema({
143151
export const rateLimitExceededError = getCorrectJsonSchema({
144152
schema: z
145153
.object({
154+
error: z.literal(true),
146155
name: z.literal("RateLimitExceededError"),
147156
id: z.literal(409),
148157
message: z.literal("Rate limit exceeded."),
@@ -153,6 +162,7 @@ export const rateLimitExceededError = getCorrectJsonSchema({
153162
}),
154163
description: "The caller has sent too many requests. Try again later.",
155164
example: {
165+
error: true,
156166
name: "RateLimitExceededError",
157167
id: 409,
158168
message: "Rate limit exceeded.",
@@ -162,16 +172,18 @@ export const rateLimitExceededError = getCorrectJsonSchema({
162172
export const validationError = getCorrectJsonSchema({
163173
schema: z
164174
.object({
165-
name: z.literal("RateLimitExceededError"),
166-
id: z.literal(104),
167-
message: z.literal("Rate limit exceeded."),
175+
error: z.literal(true),
176+
name: z.string().min(1),
177+
id: z.number(),
178+
message: z.string().min(1),
168179
})
169180
.meta({
170181
id: "validationError",
171182
description: "The request is invalid.",
172183
}),
173184
description: "The request is invalid.",
174185
example: {
186+
error: true,
175187
name: "ValidationError",
176188
id: 104,
177189
message: "Request is invalid.",

0 commit comments

Comments
 (0)