mirror of
https://github.com/frappe/books.git
synced 2025-02-02 12:08:27 +00:00
fix: Commonify error handling for document actions
This commit is contained in:
parent
fa6d519836
commit
24a768f6ad
@ -74,6 +74,7 @@
|
||||
import { _ } from 'frappejs/utils';
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import Button from '@/components/Button';
|
||||
import { handleErrorWithDialog } from '@/utils';
|
||||
|
||||
let TwoColumnForm = {
|
||||
name: 'TwoColumnForm',
|
||||
@ -149,17 +150,7 @@ let TwoColumnForm = {
|
||||
return this.doc.submit().catch(this.handleError);
|
||||
},
|
||||
handleError(e) {
|
||||
let errorMessage = _('An error occurred.');
|
||||
if (e instanceof frappe.errors.DuplicateEntryError) {
|
||||
errorMessage = _('{0} {1} already exists.', [
|
||||
this.doc.doctype,
|
||||
this.doc.name
|
||||
]);
|
||||
} else {
|
||||
errorMessage = e.message;
|
||||
}
|
||||
this.$emit('error', errorMessage);
|
||||
throw e;
|
||||
handleErrorWithDialog(e, this.doc);
|
||||
},
|
||||
async activateInlineEditing(df) {
|
||||
if (df.inline) {
|
||||
|
@ -182,7 +182,7 @@ import Row from '@/components/Row';
|
||||
import Dropdown from '@/components/Dropdown';
|
||||
import BackLink from '@/components/BackLink';
|
||||
import { openSettings } from '@/pages/Settings/utils';
|
||||
import { deleteDocWithPrompt, openQuickEdit } from '@/utils';
|
||||
import { deleteDocWithPrompt, handleErrorWithDialog } from '@/utils';
|
||||
|
||||
export default {
|
||||
name: 'InvoiceForm',
|
||||
@ -274,6 +274,7 @@ export default {
|
||||
this.routeToList();
|
||||
return;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
this.doc.on('change', ({ changed }) => {
|
||||
if (changed === this.partyField.fieldname) {
|
||||
@ -300,10 +301,13 @@ export default {
|
||||
'items',
|
||||
this.doc.items.filter(row => row.item)
|
||||
);
|
||||
await this.doc.insertOrUpdate();
|
||||
return this.doc.insertOrUpdate().catch(this.handleError);
|
||||
},
|
||||
async onSubmitClick() {
|
||||
await this.doc.submit();
|
||||
onSubmitClick() {
|
||||
return this.doc.submit().catch(this.handleError);
|
||||
},
|
||||
handleError(e) {
|
||||
handleErrorWithDialog(e, this.doc);
|
||||
},
|
||||
async fetchPartyDoc() {
|
||||
if (this.doc[this.partyField.fieldname]) {
|
||||
|
@ -84,7 +84,6 @@
|
||||
:fields="fields"
|
||||
:autosave="true"
|
||||
:column-ratio="[1.1, 2]"
|
||||
@error="showErrorDialog"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@ -96,7 +95,7 @@ import Button from '@/components/Button';
|
||||
import FormControl from '@/components/Controls/FormControl';
|
||||
import TwoColumnForm from '@/components/TwoColumnForm';
|
||||
import Dropdown from '@/components/Dropdown';
|
||||
import { deleteDocWithPrompt, openQuickEdit, showMessageDialog } from '@/utils';
|
||||
import { deleteDocWithPrompt, openQuickEdit } from '@/utils';
|
||||
|
||||
export default {
|
||||
name: 'QuickEditForm',
|
||||
@ -239,12 +238,6 @@ export default {
|
||||
}
|
||||
input.size = valueLength;
|
||||
}
|
||||
},
|
||||
|
||||
showErrorDialog(errorMessage) {
|
||||
showMessageDialog({
|
||||
message: errorMessage
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
16
src/utils.js
16
src/utils.js
@ -6,7 +6,6 @@ import { remote, shell } from 'electron';
|
||||
import router from '@/router';
|
||||
import Avatar from '@/components/Avatar';
|
||||
|
||||
|
||||
export function createNewDatabase() {
|
||||
return new Promise(resolve => {
|
||||
remote.dialog.showSaveDialog(
|
||||
@ -80,7 +79,7 @@ export function deleteDocWithPrompt(doc) {
|
||||
.then(() => resolve(true))
|
||||
.catch(e => {
|
||||
let errorMessage;
|
||||
if (e instanceof frappe.errors.LinkValidationError) {
|
||||
if (e.type === frappe.errors.LinkValidationError) {
|
||||
errorMessage = _('{0} {1} is linked with existing records.', [
|
||||
doc.doctype,
|
||||
doc.name
|
||||
@ -151,6 +150,19 @@ export function openQuickEdit({ doctype, name, hideFields, defaults = {} }) {
|
||||
});
|
||||
}
|
||||
|
||||
export function handleErrorWithDialog(e, doc) {
|
||||
let errorMessage = _('An error occurred.');
|
||||
if (e.type === frappe.errors.DuplicateEntryError) {
|
||||
errorMessage = _('{0} {1} already exists.', [doc.doctype, doc.name]);
|
||||
} else {
|
||||
errorMessage = e.message;
|
||||
}
|
||||
showMessageDialog({
|
||||
message: errorMessage
|
||||
});
|
||||
throw e;
|
||||
}
|
||||
|
||||
export function makePDF(html, destination) {
|
||||
const { BrowserWindow } = remote;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user