2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 19:09:01 +00:00

fix: validation, error display

This commit is contained in:
18alantom 2022-05-03 20:43:55 +05:30
parent 20ea214a4b
commit 456a1546a0
7 changed files with 33 additions and 13 deletions

View File

@ -291,7 +291,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
return childDoc;
}
async _validateInsert() {
async _validateSync() {
this._validateMandatory();
await this._validateFields();
}
@ -573,6 +573,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
async _preSync() {
this._setChildDocsIdx();
await this._applyFormula();
await this._validateSync();
await this.trigger('validate');
}
@ -580,7 +581,6 @@ export class Doc extends Observable<DocValue | Doc[]> {
await setName(this, this.fyo);
this._setBaseMetaValues();
await this._preSync();
await this._validateInsert();
const oldName = this.name!;
const validDict = this.getValidDict();
@ -596,8 +596,8 @@ export class Doc extends Observable<DocValue | Doc[]> {
async _update() {
await this._validateDbNotModified();
await this._preSync();
this._updateModifiedMetaValues();
await this._preSync();
const data = this.getValidDict();
await this.fyo.db.update(this.schemaName, data);

View File

@ -1,9 +1,13 @@
import { t } from './translation';
export class BaseError extends Error {
label: string;
message: string;
statusCode: number;
constructor(statusCode: number, message: string) {
super(message);
this.label = t`Base Error`;
this.name = 'BaseError';
this.statusCode = statusCode;
this.message = message;
@ -13,6 +17,7 @@ export class BaseError extends Error {
export class ValidationError extends BaseError {
constructor(message: string) {
super(417, message);
this.label = t`Validation Error`;
this.name = 'ValidationError';
}
}
@ -20,6 +25,7 @@ export class ValidationError extends BaseError {
export class NotFoundError extends BaseError {
constructor(message: string) {
super(404, message);
this.label = t`Not Found Error`;
this.name = 'NotFoundError';
}
}
@ -27,6 +33,7 @@ export class NotFoundError extends BaseError {
export class ForbiddenError extends BaseError {
constructor(message: string) {
super(403, message);
this.label = t`Forbidden Error`;
this.name = 'ForbiddenError';
}
}
@ -34,6 +41,7 @@ export class ForbiddenError extends BaseError {
export class DuplicateEntryError extends ValidationError {
constructor(message: string) {
super(message);
this.label = t`Duplicate Entry Error`;
this.name = 'DuplicateEntryError';
}
}
@ -41,6 +49,7 @@ export class DuplicateEntryError extends ValidationError {
export class LinkValidationError extends ValidationError {
constructor(message: string) {
super(message);
this.label = t`Link Validation Error`;
this.name = 'LinkValidationError';
}
}
@ -48,6 +57,7 @@ export class LinkValidationError extends ValidationError {
export class MandatoryError extends ValidationError {
constructor(message: string) {
super(message);
this.label = t`Mandatory Error`;
this.name = 'MandatoryError';
}
}
@ -55,6 +65,7 @@ export class MandatoryError extends ValidationError {
export class DatabaseError extends BaseError {
constructor(message: string) {
super(500, message);
this.label = t`Database Error`;
this.name = 'DatabaseError';
}
}
@ -62,6 +73,7 @@ export class DatabaseError extends BaseError {
export class CannotCommitError extends DatabaseError {
constructor(message: string) {
super(message);
this.label = t`Cannot Commit Error`;
this.name = 'CannotCommitError';
}
}

View File

@ -66,7 +66,8 @@
{
"fieldname": "date",
"label": "Date",
"fieldtype": "Date"
"fieldtype": "Date",
"required": true
},
{
"fieldname": "accounts",

View File

@ -16,12 +16,14 @@
"fieldname": "party",
"label": "Party",
"fieldtype": "Link",
"target": "Party"
"target": "Party",
"required": true
},
{
"fieldname": "date",
"label": "Posting Date",
"fieldtype": "Date"
"fieldtype": "Date",
"required": true
},
{
"fieldname": "account",

View File

@ -16,7 +16,8 @@
{
"fieldname": "date",
"label": "Date",
"fieldtype": "Date"
"fieldtype": "Date",
"required": true
},
{
"fieldname": "party",
@ -29,7 +30,8 @@
"fieldname": "account",
"label": "Account",
"fieldtype": "Link",
"target": "Account"
"target": "Account",
"required": true
},
{
"fieldname": "currency",

View File

@ -16,7 +16,8 @@
{
"fieldname": "date",
"label": "Date",
"fieldtype": "Date"
"fieldtype": "Date",
"required": true
},
{
"fieldname": "party",
@ -29,7 +30,8 @@
"fieldname": "account",
"label": "Account",
"fieldtype": "Link",
"target": "Account"
"target": "Account",
"required": true
},
{
"fieldname": "currency",
@ -102,4 +104,4 @@
"default": "SINV-"
}
]
}
}

View File

@ -3,7 +3,7 @@ import { t } from 'fyo';
import { ConfigKeys } from 'fyo/core/types';
import { Doc } from 'fyo/model/doc';
import { TelemetrySetting } from 'fyo/telemetry/types';
import { MandatoryError, ValidationError } from 'fyo/utils/errors';
import { BaseError, MandatoryError, ValidationError } from 'fyo/utils/errors';
import { ErrorLog } from 'fyo/utils/types';
import { IPC_ACTIONS, IPC_MESSAGES } from 'utils/messages';
import { fyo } from './initFyo';
@ -106,7 +106,8 @@ export function handleErrorWithDialog(error: Error, doc?: Doc) {
const errorMessage = getErrorMessage(error, doc);
handleError(false, error, { errorMessage, doc });
showMessageDialog({ message: error.name, detail: errorMessage });
const name = (error as BaseError).label ?? error.name;
showMessageDialog({ message: name, detail: errorMessage });
throw error;
}