Skip to content

Commit

Permalink
chore: Add UNKNOWN and INVALID_ARGUMENT error types
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Jan 18, 2025
1 parent e7dcc27 commit a357b09
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/app/[locale]/_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export type TranslationParams = {
};

export type ErrorType =
| "INVALID_ARGUMENT"
| "ROMANIZE_SERVICE_UNAVAILABLE"
| "TRANSLATOR_SERVICE_UNAVAILABLE";
| "TRANSLATOR_SERVICE_UNAVAILABLE"
| "UNKNOWN";

type ResultError = {
type: "error";
error?: ErrorType;
error: ErrorType;
message?: string;
};

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

if (typeof direction !== "string") {
return {
type: "error",
error: "INVALID_ARGUMENT",
message: "翻訳方向が不正です。",
};
}

if (typeof dialect !== "string") {
return {
type: "error",
error: "INVALID_ARGUMENT",
message: "方言が不正です。",
};
}

if (typeof pronoun !== "string") {
return {
type: "error",
error: "INVALID_ARGUMENT",
message: "人称が不正です。",
};
}

if (text.length > MAX_LENGTH) {
return {
type: "error",
error: "INVALID_ARGUMENT",
message: `テキストの長さが制限を超えています。${MAX_LENGTH}文字以内にしてください。`,
};
}
Expand All @@ -96,6 +103,7 @@ export async function fetchTranslation(
console.error(error);
return {
type: "error",
error: "UNKNOWN",
message:
"エラーが発生しました。しばらく待ってから再度お試しください。",
};
Expand All @@ -119,6 +127,7 @@ export async function fetchTranslation(
console.error(error);
return {
type: "error",
error: "UNKNOWN",
message:
"エラーが発生しました。しばらく待ってから再度お試しください。",
};
Expand Down Expand Up @@ -157,6 +166,7 @@ export async function fetchTranslation(
console.log(error);
return {
type: "error",
error: "UNKNOWN",
message: "エラーが発生しました。しばらく待ってから再度お試しください。",
};
}
Expand Down

0 comments on commit a357b09

Please sign in to comment.