first commit

This commit is contained in:
Rutra committed 2026-10-12 14:25:22 +02:00
commit 3c0479faf0
169 files changed
+27617

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
import app from '@adonisjs/core/services/app'
import { type HttpContext, ExceptionHandler } from '@adonisjs/core/http'
import { isDockerUnreachable } from '#services/docker_service'
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) {
/**
* Shield redirects back on a bad CSRF token, which means nothing for
* the API: answer with a JSON error instead.
*/
if ((error as { code?: string })?.code === 'E_BAD_CSRF_TOKEN') {
return ctx.response.forbidden({
message: 'Session expirée ou jeton de sécurité invalide : recharge la page.',
})
}
if (isDockerUnreachable(error)) {
return ctx.response.serviceUnavailable({
message: 'Docker est injoignable : le socket Docker est-il monté dans le conteneur ?',
})
}
/**
* Errors of the Docker API (unknown container, conflict…).
*/
const dockerError = error as { statusCode?: number; json?: { message?: string } }
if (typeof dockerError?.statusCode === 'number' && dockerError.json?.message) {
return ctx.response
.status(dockerError.statusCode === 404 ? 404 : 400)
.send({ message: `Docker : ${dockerError.json.message}` })
}
return super.handle(error, ctx)
}
/**
* The method is used to report error to the logging service or
* the a 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)
}
}
+18
View File
@@ -0,0 +1,18 @@
import { Exception } from '@adonisjs/core/exceptions'
import type { HttpContext } from '@adonisjs/core/http'
/**
* An error whose message is meant for the user (shown as is in the
* dashboard). Defaults to a 400 status.
*/
export default class UserError extends Exception {
static status = 400
constructor(message: string, status?: number) {
super(message, { status: status ?? UserError.status })
}
async handle(error: this, ctx: HttpContext) {
ctx.response.status(error.status).send({ message: error.message })
}
}