Skip to content
Snippets Groups Projects
Commit 1a2119a1 authored by Lucas Fernandes de Oliveira's avatar Lucas Fernandes de Oliveira
Browse files

Issue #28: Add error field in API error responses

parent a4f36ad1
No related branches found
No related tags found
1 merge request!32Issue #28: Add error field in API error responses
Pipeline #
...@@ -52,9 +52,12 @@ describe("API data controller", () => { ...@@ -52,9 +52,12 @@ describe("API data controller", () => {
.expect((res: any) => { .expect((res: any) => {
const message = "Query execution failed: " + const message = "Query execution failed: " +
"Could not construct query with the paramters given."; "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.be.an("object");
expect(res.body).to.have.property("message"); 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.message).to.be.eql(message);
expect(res.body.error).to.be.eql(error);
}) })
.end(done); .end(done);
}); });
...@@ -67,9 +70,12 @@ describe("API data controller", () => { ...@@ -67,9 +70,12 @@ describe("API data controller", () => {
.expect((res: any) => { .expect((res: any) => {
const message = "Query execution failed: " + const message = "Query execution failed: " +
"Could not construct query with the paramters given."; "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.be.an("object");
expect(res.body).to.have.property("message"); 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.message).to.be.eql(message);
expect(res.body.error).to.be.eql(error);
}) })
.end(done); .end(done);
}); });
......
...@@ -48,15 +48,21 @@ export class DataCtrl { ...@@ -48,15 +48,21 @@ export class DataCtrl {
view = req.engine.query(query); view = req.engine.query(query);
} }
catch (e) { catch (e) {
res.status(500).json({ message: "Query execution failed: " + res.status(500).json({
"Could not construct query with the paramters given." }); message: "Query execution failed: " +
"Could not construct query with the paramters given.",
error: e.message
});
return; return;
} }
req.adapter.getDataFromView(view, (err: Error, result: any[]) => { req.adapter.getDataFromView(view, (err: Error, result: any[]) => {
if (err) { if (err) {
res.status(500).json({ message: "Query execution failed " + res.status(500).json({
"failed on execute query on database." }); message: "Query execution failed " +
"failed on execute query on database.",
error: err
});
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment