Skip to content

Commit

Permalink
Error Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vr-varad committed Feb 17, 2025
1 parent 859e047 commit 6d897cc
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/ErrorHandler/index.js
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
}
12 changes: 12 additions & 0 deletions packages/ErrorHandler/package.json
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"
}

0 comments on commit 6d897cc

Please sign in to comment.