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

View File

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

View File

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

View File

@ -4,21 +4,21 @@ module.exports = app => {
app.get(`/api/report/:name`, async(req, res, next) => { app.get(`/api/report/:name`, async(req, res, next) => {
const args = req.query; const args = req.query;
const requiredArgs = ['clientId']; const requiredArgs = ['clientId'];
const argList = requiredArgs.join(',');
const hasRequiredArgs = requiredArgs.every(arg => { const hasRequiredArgs = requiredArgs.every(arg => {
return args[arg]; return args[arg];
}); });
if (!hasRequiredArgs)
res.json({message: 'Required params recipient, clientId'});
try { try {
if (!hasRequiredArgs)
throw new Error(`Required properties not found [${argList}]`);
const report = new Report(req.params.name, args); const report = new Report(req.params.name, args);
const stream = await report.toPdfStream(); const stream = await report.toPdfStream();
res.setHeader('Content-type', 'application/pdf'); res.setHeader('Content-type', 'application/pdf');
stream.pipe(res); stream.pipe(res);
} catch (e) { } catch (error) {
next(e); 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> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{$t('description.dear')}},</p> <p>{{$t('description.dear')}},</p>
<p>{{$t('description.instructions')}}</p> <p>{{$t('description.instructions')}}</p>

View File

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

View File

@ -30,7 +30,7 @@
</div> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{$t('dear')}}</p> <p>{{$t('dear')}}</p>
<p v-html="$t('description', [ticketId])"></p> <p v-html="$t('description', [ticketId])"></p>
@ -38,7 +38,7 @@
</div> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-px-lg"> <div class="grid-block vn-px-lg">
<p>{{$t('copyLink')}}</p> <p>{{$t('copyLink')}}</p>
<div class="external-link vn-pa-sm vn-m-md"> <div class="external-link vn-pa-sm vn-m-md">
https://www.verdnatura.es/#!form=ecomerce/ticket&ticket={{ticketId}} https://www.verdnatura.es/#!form=ecomerce/ticket&ticket={{ticketId}}
@ -47,7 +47,7 @@
</div> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <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('poll')"></p>
<p v-html="$t('help')"></p> <p v-html="$t('help')"></p>
<p v-html="$t('conclusion')"></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> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{$t('dear')}},</p> <p>{{$t('dear')}},</p>
<p v-html="$t('description', [ticketId])"></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> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{$t('description.instructions')}}</p> <p>{{$t('description.instructions')}}</p>
</div> </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> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{ $t('sections.introduction.title') }},</p> <p>{{ $t('sections.introduction.title') }},</p>
<p>{{ $t('sections.introduction.description') }}</p> <p>{{ $t('sections.introduction.description') }}</p>
@ -65,7 +65,7 @@
</div> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row" v-if="isPreview"> <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" <attachment v-for="attachment in attachments"
v-bind:key="attachment.filename" v-bind:key="attachment.filename"
v-bind:attachment="attachment" 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> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block white vn-pa-lg"> <div class="grid-block vn-pa-lg">
<h1>{{ $t('title') }}</h1> <h1>{{ $t('title') }}</h1>
<p>{{ $t('sections.introduction.title') }},</p> <p>{{ $t('sections.introduction.title') }},</p>
<p>{{ $t('sections.introduction.description') }}</p> <p>{{ $t('sections.introduction.description') }}</p>
@ -48,7 +48,7 @@
</div> </div>
<!-- Block --> <!-- Block -->
<div class="grid-row" v-if="isPreview"> <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" <attachment v-for="attachment in attachments"
v-bind:key="attachment.filename" v-bind:key="attachment.filename"
v-bind:attachment="attachment" v-bind:attachment="attachment"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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