-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix(package): add missing TSDocs, change enum StatusCode to object …
…and add type StatusCode"
- Loading branch information
1 parent
12098d8
commit 4c9780c
Showing
13 changed files
with
267 additions
and
91 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"mode": "pre", | ||
"tag": "prerelease.2", | ||
"initialVersions": { | ||
"oh-my-error": "2.0.0-prerelease.1" | ||
}, | ||
"changesets": ["short-eels-sparkle"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"oh-my-error": major | ||
--- | ||
|
||
- Add type `StatusCode` | ||
- Add missing TSDocs | ||
- Change enum StatusCode to object |
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
dist/* | ||
lib/* | ||
pnpm-lock.yaml | ||
|
||
*.md |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable @typescript-eslint/require-await */ | ||
import { describe, expect, test } from "vitest"; | ||
import myErrorCatcher from "./myErrorCatcher"; | ||
|
||
describe("[FUNCTION] myErrorCatcher", () => { | ||
describe("[ERRORS]", () => { | ||
test("myErrorCatcher catch error and throw own error", () => { | ||
const funThrowErr = () => { | ||
throw new Error("Oh, it's Error!"); | ||
}; | ||
|
||
// eslint-disable-next-line vitest/valid-expect, @typescript-eslint/no-floating-promises, @typescript-eslint/promise-function-async | ||
expect(() => | ||
myErrorCatcher(funThrowErr)().catch(() => { | ||
throw new Error("Function Throws Error!"); | ||
}) | ||
).rejects.toThrowError("Function Throws Error!"); | ||
}); | ||
test("ASYNC myErrorCatcher catch error and throw own error", async () => { | ||
const funThrowErr = async () => { | ||
throw new Error("Oh, it's Error!"); | ||
}; | ||
|
||
// eslint-disable-next-line vitest/valid-expect, @typescript-eslint/no-floating-promises, @typescript-eslint/promise-function-async | ||
expect(() => | ||
myErrorCatcher(funThrowErr)().catch(() => { | ||
throw new Error("Function Throws Error!"); | ||
}) | ||
).rejects.toThrowError("Function Throws Error!"); | ||
}); | ||
}); | ||
describe("[PASS]", () => { | ||
test("myErrorCatcher w", async () => { | ||
const funReturnName = async (name: string) => name; | ||
|
||
// eslint-disable-next-line vitest/valid-expect, @typescript-eslint/no-floating-promises, @typescript-eslint/promise-function-async | ||
expect( | ||
await myErrorCatcher(funReturnName)("John").catch(() => { | ||
throw new Error("Function Throws Error!"); | ||
}) | ||
).toBe("John"); | ||
}); | ||
test("ASYNC myErrorCatcher catch error and throw own error", async () => { | ||
const funThrowErr = async () => { | ||
throw new Error("Oh, it's Error!"); | ||
}; | ||
|
||
// eslint-disable-next-line vitest/valid-expect, @typescript-eslint/no-floating-promises, @typescript-eslint/promise-function-async | ||
expect(() => | ||
myErrorCatcher(funThrowErr)().catch(() => { | ||
throw new Error("Function Throws Error!"); | ||
}) | ||
).rejects.toThrowError("Function Throws 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,10 +1,27 @@ | ||
import type { arrowFunction } from "@/types/internal"; | ||
|
||
/** | ||
* Promise Wrapper. | ||
* | ||
* | ||
* @param functionThatMayThrow - The error code to handle. | ||
* @param errorSolutions - An object containing error handling functions, keyed by error codes. | ||
* | ||
* @returns `functionThatMayThrow` wrapped in Promise | ||
* | ||
* @example | ||
* ``` | ||
* const data = await myErrorCatcher(readFile)("path...").catch(() => { | ||
* // Code before crash... | ||
* throw new Error("Can't read file!"); | ||
* }); | ||
* ``` | ||
*/ | ||
export const myErrorCatcher = | ||
<T extends arrowFunction<T>>(functionThatMayThrow: T) => | ||
async (...arguments_: Parameters<T>): Promise<ReturnType<T>> => | ||
async (...args: Parameters<T>): Promise<ReturnType<T>> => | ||
new Promise(resolve => { | ||
resolve(functionThatMayThrow(...arguments_)); | ||
resolve(functionThatMayThrow(...args)); | ||
}); | ||
|
||
export default myErrorCatcher; |
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
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
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
Oops, something went wrong.