Add initial project files

This commit is contained in:
Igor Martyniuk
2026-09-01 13:03:41 +03:00
parent 22e111bb44
commit 74cb5b6176
1841 changed files with 242819 additions and 30 deletions
@@ -0,0 +1,8 @@
import { Exception } from '@adonisjs/core/exceptions'
import type { HttpContext } from '@adonisjs/core/http'
export default class ApiException extends Exception {
async handle(error: this, ctx: HttpContext) {
ctx.response.status(error.status).send({ message: error.message, code: error.code })
}
}
@@ -0,0 +1,55 @@
import ApiException from '#exceptions/api_exception'
export class FilenameMissingExtensionException extends ApiException {
static status = 400
static code = 'E_FILE_NAME_MISSING_EXTENSION'
constructor(message: string = 'File name missing extension') {
super(message)
}
}
export class EntryNameNotChangedException extends ApiException {
static status = 400
static code = 'E_ENTRY_NAME_NOT_CHANGED'
constructor(message: string = 'Entry name was not changed') {
super(message)
}
}
export class EntryExistsException extends ApiException {
static status = 400
static code = 'E_ENTRY_ALREADY_EXISTS'
constructor(message: string = 'Entry already exists') {
super(message)
}
}
export class DirExistsException extends ApiException {
static status = 400
static code = 'E_DIRECTORY_ALREADY_EXISTS'
constructor(message: string = 'Directory already exists') {
super(message)
}
}
export class FileNotFoundException extends ApiException {
static status = 404
static code = 'E_FILE_NOT_FOUND'
constructor(message: string = 'File not found') {
super(message)
}
}
export class DirNotFoundException extends ApiException {
static status = 404
static code = 'E_DIR_NOT_FOUND'
constructor(message: string = 'Directory not found') {
super(message)
}
}
+28
View File
@@ -0,0 +1,28 @@
import app from '@adonisjs/core/services/app'
import { HttpContext, ExceptionHandler } from '@adonisjs/core/http'
export default class HttpExceptionHandler extends ExceptionHandler {
/**
* In debug mode, the exception handler will display verbose errors
* with pretty printed stack traces.
*/
protected debug = !app.inProduction
/**
* The method is used for handling errors and returning
* response to the client
*/
async handle(error: unknown, ctx: HttpContext) {
return super.handle(error, ctx)
}
/**
* The method is used to report error to the logging service or
* the third party error monitoring service.
*
* @note You should not attempt to send a response from this method.
*/
async report(error: unknown, ctx: HttpContext) {
return super.report(error, ctx)
}
}
@@ -0,0 +1,55 @@
import ApiException from '#exceptions/api_exception'
export class PageNotFoundException extends ApiException {
static status = 404
static code = 'E_PAGE_NOT_FOUND'
constructor(resource: string = 'Page') {
super(`${resource} not found`)
}
}
export class PageRouteConflictException extends ApiException {
static status = 409
static code = 'E_PAGE_ROUTE_CONFLICT'
constructor(locale: string, path: string) {
super(`A page already uses /${locale}/${path}`)
}
}
export class PageNotPublishedException extends ApiException {
static status = 409
static code = 'E_PAGE_NOT_PUBLISHED'
constructor() {
super('Only a published page can be unpublished')
}
}
export class InvalidPagePayloadException extends ApiException {
static status = 422
static code = 'E_INVALID_PAGE_PAYLOAD'
constructor(message: string = 'Invalid page payload') {
super(message)
}
}
export class PageMediaFileMissingException extends ApiException {
static status = 422
static code = 'E_PAGE_MEDIA_FILE_MISSING'
constructor(fileKey: string) {
super(`Missing uploaded file for key "${fileKey}"`)
}
}
export class PageMediaFileInvalidException extends ApiException {
static status = 422
static code = 'E_PAGE_MEDIA_FILE_INVALID'
constructor(fileKey: string, message?: string) {
super(message || `Invalid uploaded file for key "${fileKey}"`)
}
}