-
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.
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 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,82 @@ | ||
class CustomError extends Error { | ||
constructor(message, status) { | ||
super(message); | ||
this.status = status; | ||
} | ||
} | ||
|
||
class UnSupportedLanguageError extends CustomError { | ||
constructor(language) { | ||
super(`Language ${language} is not supported`, 400); | ||
} | ||
} | ||
|
||
|
||
class UserCreationError extends CustomError { | ||
constructor(username) { | ||
super(`Error creating user ${username}`, 500); | ||
} | ||
} | ||
|
||
class UserDeletionError extends CustomError { | ||
constructor(username) { | ||
super(`Error deleting user ${username}`, 500); | ||
} | ||
} | ||
|
||
class UserNotFoundError extends CustomError { | ||
constructor(username) { | ||
super(`User ${username} not found`, 404); | ||
} | ||
} | ||
|
||
class ExecutionError extends CustomError { | ||
constructor(message) { | ||
super(message, 500); | ||
} | ||
} | ||
|
||
|
||
class CompilationError extends CustomError { | ||
constructor(message) { | ||
super(message, 400); | ||
} | ||
} | ||
|
||
class TimeoutError extends CustomError { | ||
constructor() { | ||
super('Execution timed out', 408); | ||
} | ||
} | ||
|
||
class InternalServerError extends CustomError { | ||
constructor(message) { | ||
super(message, 500); | ||
} | ||
} | ||
|
||
class BadRequestError extends CustomError { | ||
constructor(message) { | ||
super(message, 400); | ||
} | ||
} | ||
|
||
class ForbiddenError extends CustomError { | ||
constructor(message) { | ||
super(message, 403); | ||
} | ||
} | ||
|
||
|
||
export { | ||
UnSupportedLanguageError, | ||
UserCreationError, | ||
UserDeletionError, | ||
UserNotFoundError, | ||
ExecutionError, | ||
CompilationError, | ||
TimeoutError, | ||
InternalServerError, | ||
BadRequestError, | ||
ForbiddenError | ||
} |
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,12 @@ | ||
{ | ||
"name": "@code_blaster/error-handler", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |