Skip to content

Commit 6d897cc

Browse files
committed
Error Handler
1 parent 859e047 commit 6d897cc

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

packages/ErrorHandler/index.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
class CustomError extends Error {
2+
constructor(message, status) {
3+
super(message);
4+
this.status = status;
5+
}
6+
}
7+
8+
class UnSupportedLanguageError extends CustomError {
9+
constructor(language) {
10+
super(`Language ${language} is not supported`, 400);
11+
}
12+
}
13+
14+
15+
class UserCreationError extends CustomError {
16+
constructor(username) {
17+
super(`Error creating user ${username}`, 500);
18+
}
19+
}
20+
21+
class UserDeletionError extends CustomError {
22+
constructor(username) {
23+
super(`Error deleting user ${username}`, 500);
24+
}
25+
}
26+
27+
class UserNotFoundError extends CustomError {
28+
constructor(username) {
29+
super(`User ${username} not found`, 404);
30+
}
31+
}
32+
33+
class ExecutionError extends CustomError {
34+
constructor(message) {
35+
super(message, 500);
36+
}
37+
}
38+
39+
40+
class CompilationError extends CustomError {
41+
constructor(message) {
42+
super(message, 400);
43+
}
44+
}
45+
46+
class TimeoutError extends CustomError {
47+
constructor() {
48+
super('Execution timed out', 408);
49+
}
50+
}
51+
52+
class InternalServerError extends CustomError {
53+
constructor(message) {
54+
super(message, 500);
55+
}
56+
}
57+
58+
class BadRequestError extends CustomError {
59+
constructor(message) {
60+
super(message, 400);
61+
}
62+
}
63+
64+
class ForbiddenError extends CustomError {
65+
constructor(message) {
66+
super(message, 403);
67+
}
68+
}
69+
70+
71+
export {
72+
UnSupportedLanguageError,
73+
UserCreationError,
74+
UserDeletionError,
75+
UserNotFoundError,
76+
ExecutionError,
77+
CompilationError,
78+
TimeoutError,
79+
InternalServerError,
80+
BadRequestError,
81+
ForbiddenError
82+
}

packages/ErrorHandler/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@code_blaster/error-handler",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC"
12+
}

0 commit comments

Comments
 (0)