error handling
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-06-03 08:59:31 +02:00
parent e92104f55a
commit 3576ff08e6
4 changed files with 9 additions and 9 deletions

View File

@ -25,7 +25,7 @@ router.get('/:smartTagFk&:shelving&:level', async(req, res) => {
module.exports = router;
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
async function insertShelving(shelvingId, smartTagFk) {
async function insertShelving(shelvingId, smartTagFk, res) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
@ -52,7 +52,7 @@ async function insertShelving(shelvingId, smartTagFk) {
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'bindingCreateError', message: response.body.message}});
return res.status(400).json({error: {code: 'bindingCreateError', message: response.body.message}});
response = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
json: {
@ -69,5 +69,5 @@ async function insertShelving(shelvingId, smartTagFk) {
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
return res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
}

View File

@ -10,7 +10,7 @@ router.get('/:collectionFk', async(req, res) => {
const collectionFk = req.params.collectionFk;
const [collection] = await collectionSmartTag(collectionFk);
if (!collection.length)
res.status(400).json({error: {code: 'emptyCollectionSmartTag', message: 'No hay datos'}});
return res.status(400).json({error: {code: 'emptyCollectionSmartTag', message: 'No hay datos'}});
await insertTicket(collection);

View File

@ -10,7 +10,7 @@ router.get('/:ticket', async(req, res) => {
const [ticket] = await selectTicket(ticketId);
if (!ticket.length)
res.status(400).json({error: {code: 'flashError', message: 'Este ticket no está asociado'}});
return res.status(400).json({error: {code: 'flashError', message: 'Este ticket no está asociado'}});
await insertFlash(ticket);
@ -19,7 +19,7 @@ router.get('/:ticket', async(req, res) => {
module.exports = router;
async function insertFlash(ticket) {
async function insertFlash(ticket, res) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
@ -38,5 +38,5 @@ async function insertFlash(ticket) {
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'flashError', message: response.body.message}});
return res.status(400).json({error: {code: 'flashError', message: response.body.message}});
}

View File

@ -2,14 +2,14 @@ const con = require('../db/connect');
function isSmartTag(toFilter, res) {
const exp = /^A0A3B82[A-F0-9]{5}$/;
if (!exp.test(toFilter))
res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
return res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
}
async function isShelving(shelving, res) {
const sql = `SELECT * FROM vn.shelving WHERE code = ?`;
const [response] = await con.query(sql, shelving);
if (response.length == 0)
res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
return res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
}
exports.isSmartTag = isSmartTag;