Skip to content

Commit 4993e80

Browse files
author
Lukas Siemon
committed
feat: throwing error if GET method with json parameters is used
1 parent 1352504 commit 4993e80

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ module.exports = (options = {}) => {
5656
const limiter = Limiter(get(options, 'limiter', {}));
5757

5858
const wrap = (request, params, limit, handler) => {
59+
if (request.startsWith("GET ") && params.filter(p => p.position === 'json').length !== 0) {
60+
throw new Error("Can not use JSON parameter with GET requests.");
61+
}
5962
const parser = Parser(request, params);
6063
return rollbar
6164
.wrap((event, context, callback, rb) => limiter

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"author": "Lukas Siemon",
1515
"devDependencies": {
1616
"app-root-path": "2.0.1",
17+
"chai": "4.1.2",
1718
"coveralls": "3.0.0",
1819
"js-gardener": "1.11.18",
1920
"semantic-release": "12.4.1",

test/test_param.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const expect = require('chai').expect;
2+
const api = require("../lib/api")();
3+
4+
describe("Testing Params", () => {
5+
it("Testing Error for GET And JSON Param", (done) => {
6+
expect(() => api.wrap("GET route", [api.Str("name", "json")], 1, () => {}))
7+
.to.throw("Can not use JSON parameter with GET requests.");
8+
done();
9+
});
10+
});

0 commit comments

Comments
 (0)