Commit b45bb4cf authored by Anne Blankert's avatar Anne Blankert

improved error response

parent 8906cf67
...@@ -45,15 +45,20 @@ module.exports = function (app, pool) { ...@@ -45,15 +45,20 @@ module.exports = function (app, pool) {
const result = await pool.query(sqlString); const result = await pool.query(sqlString);
res.json(result.rows); res.json(result.rows);
} catch (err) { } catch (err) {
console.log(err);
let status = 500;
switch (err.code) { switch (err.code) {
case '42P01': case '42P01':
err.name = `table ${req.params.table} does not exist`; // table does not exist
status = 422;
break; break;
case '42703': case '42703':
err.name = `column does not exist`; // column does not exist
status = 422;
break; 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