This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: errors.tsとerrors.test.tsを修正、src/entry/main.tsにimportの記述を追加
- Loading branch information
Showing
3 changed files
with
46 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
// function that takes an error type and returns a string type | ||
// the errors in the conversion source is defined in ../service/entry.test.ts | ||
// the error code of the conversion destination is written in README.md | ||
import { describe, it, expect } from "vitest"; | ||
|
||
function errorToCode(error: Error): string { | ||
switch (error.message) { | ||
case "too many members": | ||
return "TOO_MANY_MEMBERS"; | ||
case "no member": | ||
return "NO_MEMBER"; | ||
case "teamName Exists": | ||
return "TEAM_ALREADY_EXISTS"; | ||
default: | ||
return "UNKNOWN_ERROR"; | ||
} | ||
} | ||
describe("正しくエラーコードに変換できる", () => { | ||
const errorToCode = (error: Error) => { | ||
switch (error.message) { | ||
case "too many members": | ||
return "TOO_MANY_MEMBERS"; | ||
case "no member": | ||
return "NO_MEMBER"; | ||
case "teamName Exists": | ||
return "TEAM_ALREADY_EXISTS"; | ||
default: | ||
return "UNKNOWN_ERROR"; | ||
} | ||
}; | ||
it("too many members", () => { | ||
const error = new Error("too many members"); | ||
expect(errorToCode(error)).toBe("TOO_MANY_MEMBERS"); | ||
}); | ||
it("no member", () => { | ||
const error = new Error("no member"); | ||
expect(errorToCode(error)).toBe("NO_MEMBER"); | ||
}); | ||
it("teamName Exists", () => { | ||
const error = new Error("teamName Exists"); | ||
expect(errorToCode(error)).toBe("TEAM_ALREADY_EXISTS"); | ||
}); | ||
|
||
it("other", () => { | ||
const error = new Error("other"); | ||
expect(errorToCode(error)).toBe("UNKNOWN_ERROR"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
// write something here | ||
export { errorToCode }; | ||
function errorToCode(error: Error): string { | ||
switch (error.message) { | ||
case "too many members": | ||
return "TOO_MANY_MEMBERS"; | ||
case "no member": | ||
return "NO_MEMBER"; | ||
case "teamName Exists": | ||
return "TEAM_ALREADY_EXISTS"; | ||
default: | ||
return "UNKNOWN_ERROR"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters