refactor: el UserError se lanza en back
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2022-10-26 09:33:03 +02:00
parent c77999871e
commit ec81b12239
2 changed files with 2 additions and 3 deletions

View File

@ -1,5 +1,6 @@
const JSZip = require('jszip'); const JSZip = require('jszip');
const fs = require('fs-extra'); const fs = require('fs-extra');
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('downloadZip', { Self.remoteMethodCtx('downloadZip', {
@ -34,7 +35,7 @@ module.exports = Self => {
let totalSize = 0; let totalSize = 0;
const zipConfig = await models.ZipConfig.findOne(); const zipConfig = await models.ZipConfig.findOne();
for (let id of ids) { for (let id of ids) {
if (zipConfig && totalSize > zipConfig.maxSize) return false; if (zipConfig && totalSize > zipConfig.maxSize) throw new UserError('Files are too large');
const invoiceOutPdf = await models.InvoiceOut.download(ctx, id, myOptions); const invoiceOutPdf = await models.InvoiceOut.download(ctx, id, myOptions);
const fileName = extractFileName(invoiceOutPdf[2]); const fileName = extractFileName(invoiceOutPdf[2]);
const body = invoiceOutPdf[0]; const body = invoiceOutPdf[0];

View File

@ -1,6 +1,5 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
const UserError = require('vn-loopback/util/user-error');
export default class Controller extends Section { export default class Controller extends Section {
get checked() { get checked() {
@ -35,7 +34,6 @@ export default class Controller extends Section {
}; };
this.$http.post(`InvoiceOuts/downloadZip`, params) this.$http.post(`InvoiceOuts/downloadZip`, params)
.then(res => { .then(res => {
if (res.data == false) throw new UserError('Files are too large');
location.href = 'data:application/zip;base64,' + res.data; location.href = 'data:application/zip;base64,' + res.data;
}); });
} }