Commit 8906cf67 authored by Anne Blankert's avatar Anne Blankert

improved error response

parent 14e30206
......@@ -103,15 +103,19 @@ const sql = (params, query) => {
res.set('Content-Type', 'text/x-protobuf').send(result.rows[0].st_asgeobuf);
} 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
......@@ -103,15 +103,19 @@ module.exports = function(app, pool) {
res.json(result.rows[0].geojson)
} 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