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
break; status = 422;
case '42703': break;
err.name = `column does not exist`; case '42703':
break; // column does not exist
} status = 422;
res.status(422).json({error: err}); break;
default:
}
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