Skip to content

Commit a357b09

Browse files
committed
chore: Add UNKNOWN and INVALID_ARGUMENT error types
1 parent e7dcc27 commit a357b09

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/app/[locale]/_server.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ export type TranslationParams = {
2121
};
2222

2323
export type ErrorType =
24+
| "INVALID_ARGUMENT"
2425
| "ROMANIZE_SERVICE_UNAVAILABLE"
25-
| "TRANSLATOR_SERVICE_UNAVAILABLE";
26+
| "TRANSLATOR_SERVICE_UNAVAILABLE"
27+
| "UNKNOWN";
2628

2729
type ResultError = {
2830
type: "error";
29-
error?: ErrorType;
31+
error: ErrorType;
3032
message?: string;
3133
};
3234

@@ -50,34 +52,39 @@ export async function fetchTranslation(
5052
if (typeof text !== "string" || text.length === 0) {
5153
return {
5254
type: "error",
55+
error: "INVALID_ARGUMENT",
5356
message: "テキストが入力されていません。",
5457
};
5558
}
5659

5760
if (typeof direction !== "string") {
5861
return {
5962
type: "error",
63+
error: "INVALID_ARGUMENT",
6064
message: "翻訳方向が不正です。",
6165
};
6266
}
6367

6468
if (typeof dialect !== "string") {
6569
return {
6670
type: "error",
71+
error: "INVALID_ARGUMENT",
6772
message: "方言が不正です。",
6873
};
6974
}
7075

7176
if (typeof pronoun !== "string") {
7277
return {
7378
type: "error",
79+
error: "INVALID_ARGUMENT",
7480
message: "人称が不正です。",
7581
};
7682
}
7783

7884
if (text.length > MAX_LENGTH) {
7985
return {
8086
type: "error",
87+
error: "INVALID_ARGUMENT",
8188
message: `テキストの長さが制限を超えています。${MAX_LENGTH}文字以内にしてください。`,
8289
};
8390
}
@@ -96,6 +103,7 @@ export async function fetchTranslation(
96103
console.error(error);
97104
return {
98105
type: "error",
106+
error: "UNKNOWN",
99107
message:
100108
"エラーが発生しました。しばらく待ってから再度お試しください。",
101109
};
@@ -119,6 +127,7 @@ export async function fetchTranslation(
119127
console.error(error);
120128
return {
121129
type: "error",
130+
error: "UNKNOWN",
122131
message:
123132
"エラーが発生しました。しばらく待ってから再度お試しください。",
124133
};
@@ -157,6 +166,7 @@ export async function fetchTranslation(
157166
console.log(error);
158167
return {
159168
type: "error",
169+
error: "UNKNOWN",
160170
message: "エラーが発生しました。しばらく待ってから再度お試しください。",
161171
};
162172
}

0 commit comments

Comments
 (0)