Skip to content

Commit d52c76e

Browse files
committed
feat: Add handleError function which reduce code redundancy while handling errors
1 parent a31fd4a commit d52c76e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/core/error/handle.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Jrror, { JoorError } from "@/core/error";
2+
import logger from "@/helpers/joorLogger";
3+
4+
/**
5+
* Handles errors by checking their type and calling the appropriate method.
6+
* If the error is not an instance of Jrror or JoorError, it logs the error.
7+
*
8+
* @param {unknown} error - The error to handle.
9+
*
10+
* Meant to reduce code duplication while handling errors in the codebase.
11+
*/
12+
function handleError(error: unknown): void {
13+
if (error instanceof Jrror || error instanceof JoorError) {
14+
error.handle();
15+
} else {
16+
logger.error(error);
17+
}
18+
}
19+
20+
export default handleError;

0 commit comments

Comments
 (0)