Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 6 additions & 8 deletions app/server/routers/learn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ export const learnRouting = {
.input(
z.object({
name: z.string().min(1).max(100),
list: z
.array(
z.object({
vraag: z.string().min(1).max(100),
antwoord: z.string().min(1).max(100),
}),
)
.max(1500),
list: z.array(
z.object({
vraag: z.string().min(1).max(100),
antwoord: z.string().min(1).max(100),
}),
),
id: z.uuid().optional(),
language: z.enum(taalSlugsList),
fromLanguage: z.enum(taalSlugsList),
Expand Down
6 changes: 5 additions & 1 deletion app/utils/error-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type ErrorLike = {
message?: unknown;
data?: {
code?: unknown;
zodError?: unknown;
};
shape?: {
message?: unknown;
Expand Down Expand Up @@ -87,14 +88,17 @@ export function getErrorMessage(
fallbackKey = "errors.api.generic",
): string {
const code = getCode(error);
const text = getText(error);
if (code === "BAD_REQUEST" && text && !asErrorLike(error)?.data?.zodError) {
return text;
}
if (code) {
const key = codeToTranslationKey[code];
if (key) {
return i18next.t(key);
}
}

const text = getText(error);
if (text) {
if (isNetworkError(text)) {
return i18next.t("errors.api.network");
Expand Down
2 changes: 1 addition & 1 deletion tests/trpc.endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe("tRPC endpoints (integration)", () => {
createdListIds.add(created.id);
expect(created.listItems.length).toBe(1500);

await expect(save(caller, 1501)).rejects.toThrow();
expect(save(caller, 1501)).rejects.toThrow("maximaal 1500");
});
});
});
Expand Down
Loading