add new error classes, add types and services for api keys, use new error classes in webhook api

This commit is contained in:
Matthias Nannt
2023-06-13 15:07:15 +02:00
parent c16708d12a
commit 0feaadcbc9
18 changed files with 311 additions and 93 deletions
+83
View File
@@ -0,0 +1,83 @@
class ResourceNotFoundError extends Error {
statusCode = 404;
constructor(resource: string, id: string) {
super(`${resource} with ID ${id} not found`);
this.name = "ResourceNotFoundError";
}
}
class InvalidInputError extends Error {
statusCode = 400;
constructor(message: string) {
super(message);
this.name = "InvalidInputError";
}
}
class ValidationError extends Error {
statusCode = 400;
constructor(message: string) {
super(message);
this.name = "ValidationError";
}
}
class DatabaseError extends Error {
statusCode = 500;
constructor(message: string) {
super(message);
this.name = "DatabaseError";
}
}
class UniqueConstraintError extends Error {
statusCode = 409;
constructor(message: string) {
super(message);
this.name = "UniqueConstraintError";
}
}
class ForeignKeyConstraintError extends Error {
statusCode = 409;
constructor(message: string) {
super(message);
this.name = "ForeignKeyConstraintError";
}
}
class OperationNotAllowedError extends Error {
statusCode = 403;
constructor(message: string) {
super(message);
this.name = "OperationNotAllowedError";
}
}
class AuthenticationError extends Error {
statusCode = 401;
constructor(message: string) {
super(message);
this.name = "AuthenticationError";
}
}
class AuthorizationError extends Error {
statusCode = 403;
constructor(message: string) {
super(message);
this.name = "AuthorizationError";
}
}
export {
ResourceNotFoundError,
InvalidInputError,
ValidationError,
DatabaseError,
UniqueConstraintError,
ForeignKeyConstraintError,
OperationNotAllowedError,
AuthenticationError,
AuthorizationError,
};
+1
View File
@@ -1,2 +1,3 @@
export * from "./functions";
export * from "./result";
export * from "./errors";