Issue #28: Add error field in API error responses

Signed-off-by: Lucas Fernandes de Oliveira's avatarLucas Fernandes de Oliveira <lfo14@inf.ufpr.br>
parent a4f36ad1
Pipeline #11731 passed with stage
in 1 minute and 1 second
......@@ -52,9 +52,12 @@ describe("API data controller", () => {
.expect((res: any) => {
const message = "Query execution failed: " +
"Could not construct query with the paramters given.";
const error = "The metric named met:-1 was not found";
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message");
expect(res.body).to.have.property("error");
expect(res.body.message).to.be.eql(message);
expect(res.body.error).to.be.eql(error);
})
.end(done);
});
......@@ -67,9 +70,12 @@ describe("API data controller", () => {
.expect((res: any) => {
const message = "Query execution failed: " +
"Could not construct query with the paramters given.";
const error = "The dimension named dim:11 was not found";
expect(res.body).to.be.an("object");
expect(res.body).to.have.property("message");
expect(res.body).to.have.property("error");
expect(res.body.message).to.be.eql(message);
expect(res.body.error).to.be.eql(error);
})
.end(done);
});
......
......@@ -48,15 +48,21 @@ export class DataCtrl {
view = req.engine.query(query);
}
catch (e) {
res.status(500).json({ message: "Query execution failed: " +
"Could not construct query with the paramters given." });
res.status(500).json({
message: "Query execution failed: " +
"Could not construct query with the paramters given.",
error: e.message
});
return;
}
req.adapter.getDataFromView(view, (err: Error, result: any[]) => {
if (err) {
res.status(500).json({ message: "Query execution failed " +
"failed on execute query on database." });
res.status(500).json({
message: "Query execution failed " +
"failed on execute query on database.",
error: err
});
return;
}
......
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