Commit b45bb4cf authored by Anne Blankert's avatar Anne Blankert

improved error response

parent 8906cf67
......@@ -45,15 +45,20 @@ module.exports = function (app, pool) {
const result = await pool.query(sqlString);
res.json(result.rows);
} catch (err) {
console.log(err);
let status = 500;
switch (err.code) {
case '42P01':
err.name = `table ${req.params.table} does not exist`;
// table does not exist
status = 422;
break;
case '42703':
err.name = `column does not exist`;
// column does not exist
status = 422;
break;
default:
}
res.status(422).json({error: err});
res.status(status).json({error:err.message})
}
})
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment