forked from geolba/tethys.backend
- typsafe vanilla_error_reporter.ts
- updated Dockerfole for using node 20 - remove validator_old.ts - npm updates
This commit is contained in:
parent
ec17d79cf2
commit
770e791613
9 changed files with 204 additions and 381 deletions
|
@ -4,7 +4,7 @@ import User from '#models/user';
|
|||
import TwoFactorAuthProvider from '#app/services/TwoFactorAuthProvider';
|
||||
import hash from '@adonisjs/core/services/hash';
|
||||
// import { schema, rules } from '@adonisjs/validator';
|
||||
import vine, { SimpleMessagesProvider } from '@vinejs/vine';
|
||||
import vine from '@vinejs/vine';
|
||||
|
||||
// Here we are generating secret and recovery codes for the user that’s enabling 2FA and storing them to our database.
|
||||
export default class UserController {
|
||||
|
|
|
@ -68,7 +68,7 @@ export default class HttpExceptionHandler extends ExceptionHandler {
|
|||
// }
|
||||
|
||||
public async handle(error: any, ctx: HttpContext) {
|
||||
const { response, request, session, inertia } = ctx;
|
||||
const { response, request, session } = ctx;
|
||||
|
||||
/**
|
||||
* Handle failed authentication attempt
|
||||
|
|
|
@ -17,7 +17,7 @@ export interface MessagesBagContract {
|
|||
* given validation failure.
|
||||
*/
|
||||
export class MessagesBag implements MessagesBagContract {
|
||||
messages;
|
||||
messages: Message;
|
||||
wildCardCallback;
|
||||
constructor(messages: string[]) {
|
||||
this.messages = messages;
|
||||
|
@ -66,13 +66,16 @@ export class MessagesBag implements MessagesBagContract {
|
|||
/**
|
||||
* Shape of the error message collected by the SimpleErrorReporter
|
||||
*/
|
||||
// type SimpleError = {
|
||||
// message: string;
|
||||
// field: string;
|
||||
// rule: string;
|
||||
// index?: number;
|
||||
// meta?: Record<string, any>;
|
||||
// };
|
||||
type SimpleError = {
|
||||
message: string;
|
||||
field: string;
|
||||
rule: string;
|
||||
index?: number;
|
||||
meta?: Record<string, any>;
|
||||
};
|
||||
export interface Message {
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* Simple error reporter collects error messages as an array of object.
|
||||
* Each object has following properties.
|
||||
|
@ -84,7 +87,7 @@ export class MessagesBag implements MessagesBagContract {
|
|||
* - args?: Record<string, any>
|
||||
*/
|
||||
export class VanillaErrorReporter implements ErrorReporterContract {
|
||||
private messages;
|
||||
// private messages;
|
||||
// private bail;
|
||||
/**
|
||||
* Boolean to know one or more errors have been reported
|
||||
|
@ -94,7 +97,7 @@ export class VanillaErrorReporter implements ErrorReporterContract {
|
|||
* Collection of errors
|
||||
*/
|
||||
// errors: SimpleError[] = [];
|
||||
errors = {};
|
||||
errors: Message = {};
|
||||
/**
|
||||
* Report an error.
|
||||
*/
|
||||
|
@ -117,7 +120,12 @@ export class VanillaErrorReporter implements ErrorReporterContract {
|
|||
// }
|
||||
// this.errors.push(error);
|
||||
this.hasErrors = true;
|
||||
const error = {
|
||||
// if (this.errors[field.getFieldPath()]) {
|
||||
// this.errors[field.getFieldPath()]?.push(message);
|
||||
// } else {
|
||||
// this.errors[field.getFieldPath()] = [message];
|
||||
// }
|
||||
const error: SimpleError = {
|
||||
message,
|
||||
rule,
|
||||
field: field.getFieldPath(),
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue