Files
sonixd/src/server/utils/api-error.ts
jeffvli e8fe86ea4e Fix session auth
Add custom session secret
Set session to rolling
30 day expiry
10 minute check
Custom cookie name
2022-05-03 15:31:21 -07:00

41 lines
959 B
TypeScript

class ApiError extends Error {
message: string;
statusCode: number;
constructor(options: { statusCode: number; message: string }) {
super(options.message);
this.message = options.message;
this.statusCode = options.statusCode;
}
static badRequest(message: string) {
return new ApiError({ statusCode: 400, message });
}
static unauthorized(message: string) {
return new ApiError({ statusCode: 401, message });
}
static forbidden(message: string) {
return new ApiError({ statusCode: 403, message });
}
static notFound(message: string) {
return new ApiError({ statusCode: 404, message });
}
static conflict(message: string) {
return new ApiError({ statusCode: 409, message });
}
static gone(message: string) {
return new ApiError({ statusCode: 410, message });
}
static internal(message: string) {
return new ApiError({ statusCode: 500, message });
}
}
export default ApiError;