Skip to content

Commit 6c62307

Browse files
committed
added error handling to return empty data array when invalid enum parameters are passed
1 parent f3ff5ac commit 6c62307

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

v2/definitions/econs.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,19 @@ module.exports = function (req, res, next, cb) {
5151
}
5252

5353
larkin.queryPg("burwell", sql, params, function (error, data) {
54+
console.log("CALLBACK DATA ", cb);
5455
if (error) {
56+
console.log("The error still returned from larkin")
5557
if (cb) {
5658
cb(error);
59+
} else if (error == "{\"success\":{\"v\":2,\"license\":\"CC-BY 4.0\",\"data\":[]}}") {
60+
console.log("THIS IS A SUCCESS JSON EVEN THOUGH IT'S CALLED ERROR", error)
61+
error = JSON.parse(error);
62+
res.status(200).json(error);
5763
} else {
58-
return larkin.error(req, res, next, error);
64+
larkin.error(req, res, next, error);
5965
}
66+
return
6067
}
6168

6269
if (cb) {

v2/larkin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ const { Client, Pool } = require("pg");
112112
connectionDetails.database = 'rockd'
113113
}
114114
}
115-
//TODO add error handling to keep api running if there are connection issues. Maybe implement pgpromise similar to rockd api?
116-
117115
const pool = new Pool(connectionDetails);
118116
console.log(connectionDetails)
117+
const errorMessage = "invalid input value for enum";
119118

120119
pool.connect(function (err, client, done) {
121120
if (err) {
@@ -143,7 +142,13 @@ const { Client, Pool } = require("pg");
143142
done();
144143
if (err) {
145144
larkin.log("error", err);
146-
callback(err);
145+
if (err.message.includes(errorMessage)) {
146+
const enumError = JSON.stringify({"success": {"v": 2,"license": "CC-BY 4.0", "data": []}});
147+
callback(enumError);
148+
}
149+
else {
150+
callback(err);
151+
}
147152
} else {
148153
callback(null, result);
149154
}

0 commit comments

Comments
 (0)