Commit e034df60 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira

Merge branch 'issue/28' into 'master'

Issue #28: Add error field in API error responses

See merge request !32
parents a4f36ad1 1a2119a1
Pipeline #11732 passed with stage
in 42 seconds
......@@ -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