error handling fixes
gitea/salix/dev This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-11-19 10:32:09 +01:00
parent cba578d42e
commit ed5458a264
23 changed files with 86 additions and 85 deletions

View File

@ -15,6 +15,7 @@
.grid-block {
box-sizing: border-box;
background-color: #FFF;
min-height: 40px
}
@ -22,10 +23,6 @@
height: 40px
}
.grid-block.white {
background-color: #FFF
}
.columns {
overflow: hidden;
box-sizing: border-box;

View File

@ -16,7 +16,7 @@ const validator = {
if (invalidProps.length > 0) {
const required = invalidProps.join(', ');
throw new Error(`Required params not found [${required}]`);
throw new Error(`Required properties not found [${required}]`);
}
},
props: ['isPreview']

View File

@ -1,33 +1,32 @@
const Email = require('../core/email');
module.exports = app => {
app.get(`/api/email/:name`, async(req, res) => {
app.get(`/api/email/:name`, async(req, res, next) => {
const args = req.query;
const requiredArgs = ['recipient', 'clientId'];
const requiredArgs = ['clientId', 'recipient'];
const argList = requiredArgs.join(',');
const hasRequiredArgs = requiredArgs.every(arg => {
return args[arg];
});
if (!hasRequiredArgs) {
return res.status(400).json({
message: 'Required params recipient, clientId'
});
}
try {
if (!hasRequiredArgs)
throw new Error(`Required properties not found [${argList}]`);
const email = new Email(req.params.name, args);
if (args.isPreview === 'true') {
const rendered = await email.render();
res.send(rendered);
} else await email.send();
} else {
await email.send();
res.status(200).json({
message: 'Sent'
});
}
} catch (e) {
console.error(e);
return res.status(500).json({message: 'Email not sent'});
next(e);
}
res.status(200).json({message: 'Sent'});
});
};

View File

@ -4,21 +4,21 @@ module.exports = app => {
app.get(`/api/report/:name`, async(req, res, next) => {
const args = req.query;
const requiredArgs = ['clientId'];
const argList = requiredArgs.join(',');
const hasRequiredArgs = requiredArgs.every(arg => {
return args[arg];
});
if (!hasRequiredArgs)
res.json({message: 'Required params recipient, clientId'});
try {
if (!hasRequiredArgs)
throw new Error(`Required properties not found [${argList}]`);
const report = new Report(req.params.name, args);
const stream = await report.toPdfStream();
res.setHeader('Content-type', 'application/pdf');
stream.pipe(res);
} catch (e) {
next(e);
} catch (error) {
next(error);
}
});
};

View File

@ -1,4 +1,6 @@
[{
"filename": "claim-pickup-order.pdf",
"component": "claim-pickup"
}]
[
{
"filename": "claim-pickup-order.pdf",
"component": "claim-pickup"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('description.dear')}},</p>
<p>{{$t('description.instructions')}}</p>

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('dearClient')}},</p>
<p v-html="$t('clientData')"></p>

View File

@ -30,7 +30,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('dear')}}</p>
<p v-html="$t('description', [ticketId])"></p>
@ -38,7 +38,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-px-lg">
<div class="grid-block vn-px-lg">
<p>{{$t('copyLink')}}</p>
<div class="external-link vn-pa-sm vn-m-md">
https://www.verdnatura.es/#!form=ecomerce/ticket&ticket={{ticketId}}
@ -47,7 +47,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<p v-html="$t('poll')"></p>
<p v-html="$t('help')"></p>
<p v-html="$t('conclusion')"></p>

View File

@ -1,4 +1,6 @@
[{
"filename": "delivery-note.pdf",
"component": "delivery-note"
}]
[
{
"filename": "delivery-note.pdf",
"component": "delivery-note"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('dear')}},</p>
<p v-html="$t('description', [ticketId])"></p>

View File

@ -1,4 +1,6 @@
[{
"filename": "driver-route.pdf",
"component": "driver-route"
}]
[
{
"filename": "driver-route.pdf",
"component": "driver-route"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('description.instructions')}}</p>
</div>

View File

@ -1,4 +1,6 @@
[{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}]
[
{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{ $t('sections.introduction.title') }},</p>
<p>{{ $t('sections.introduction.description') }}</p>
@ -65,7 +65,7 @@
</div>
<!-- Block -->
<div class="grid-row" v-if="isPreview">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<attachment v-for="attachment in attachments"
v-bind:key="attachment.filename"
v-bind:attachment="attachment"

View File

@ -1,4 +1,6 @@
[{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}]
[
{
"filename": "letter-debtor.pdf",
"component": "letter-debtor"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{ $t('sections.introduction.title') }},</p>
<p>{{ $t('sections.introduction.description') }}</p>
@ -48,7 +48,7 @@
</div>
<!-- Block -->
<div class="grid-row" v-if="isPreview">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<attachment v-for="attachment in attachments"
v-bind:key="attachment.filename"
v-bind:attachment="attachment"

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{ $t('sections.introduction.title') }},</p>
<p v-html="`${$t('sections.introduction.description')}:`"></p>

View File

@ -1,12 +1,14 @@
[{
"filename": "model.ezp",
"component": "printer-setup",
"path": "/assets/files/model.ezp",
"cid": "model.ezp"
},
{
"filename": "port.png",
"component": "printer-setup",
"path": "/assets/files/port.png",
"cid": "port.png"
}]
[
{
"filename": "model.ezp",
"component": "printer-setup",
"path": "/assets/files/model.ezp",
"cid": "model.ezp"
},
{
"filename": "port.png",
"component": "printer-setup",
"path": "/assets/files/port.png",
"cid": "port.png"
}
]

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('description.dear')}},</p>
<p>{{$t('description.instructions')}}</p>
@ -43,7 +43,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{$t('sections.help.title')}}</h1>
<p>{{$t('sections.help.description')}}</p>
<p v-html="$t('sections.help.remoteSupport')"></p>
@ -51,7 +51,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<div v-if="client.salesPersonName">
{{$t('salesPersonName')}}: <strong>{{client.salesPersonName}}</strong>
</div>
@ -66,7 +66,7 @@
</div>
<!-- Block -->
<div class="grid-row" v-if="isPreview">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<attachment v-for="attachment in attachments"
v-bind:key="attachment.filename"
v-bind:attachment="attachment"

View File

@ -25,7 +25,7 @@
</div>
<!-- Block -->
<div class="grid-row">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1>
<p>{{$t('description.dear')}},</p>
<div v-html="$t('description.instructions')"></div>
@ -34,7 +34,7 @@
</div>
<!-- Attachments block -->
<div class="grid-row" v-if="isPreview">
<div class="grid-block white vn-pa-lg">
<div class="grid-block vn-pa-lg">
<attachment v-for="attachment in attachments"
v-bind:key="attachment.filename"
v-bind:attachment="attachment"

View File

@ -33,7 +33,7 @@
</tr>
<tr>
<td class="font gray uppercase">{{$t('date')}}</td>
<th>{{currentDate}}</th>
<th>{{dated}}</th>
</tr>
</tbody>
</table>

View File

@ -13,7 +13,7 @@ module.exports = {
throw new Error('Something went wrong');
},
computed: {
currentDate: function() {
dated: function() {
const filters = this.$options.filters;
return filters.date(new Date(), '%d-%m-%Y');

View File

@ -12,13 +12,6 @@ module.exports = {
if (!this.route)
throw new Error('Something went wrong');
},
computed: {
dated: function() {
const filters = this.$options.filters;
return filters.date(new Date(), '%d-%m-%Y');
}
},
methods: {
fetchRoute(id) {
return db.findOne(