adding and testing limits error response with params

This commit is contained in:
Simon Martín 2018-03-26 19:10:23 +02:00
parent 54876fa203
commit 483c263f61
5 changed files with 22 additions and 24 deletions

View File

@ -36,10 +36,8 @@ function rateLimit(userLimits, endpointGroup = null) {
if (isBlocked) {
const rateLimitError = new Error('You are over the limits.');
rateLimitError.http_status = 429;
rateLimitError.context = {
type: 'limit',
subtype: 'rate-limit'
};
rateLimitError.context = 'limit';
rateLimitError.detail = 'rate-limit';
return next(rateLimitError);
}

View File

@ -6,10 +6,8 @@ function ErrorHandler(err) {
if (this.isTimeoutError()) {
this.err = new Error('You are over platform\'s limits. Please contact us to know more details');
this.err.http_status = 429;
this.err.context = {
type: 'limit',
subtype: 'datasource'
};
this.err.context = 'limit';
this.err.detail = 'datasource';
}
}

View File

@ -793,10 +793,8 @@ it('GET with callback must return 200 status error even if it is an error', func
error: [
'You are over platform\'s limits. Please contact us to know more details'
],
context: {
subtype: "datasource",
type: "limit"
}
context: "limit",
detail: "datasource"
});
done();
@ -821,10 +819,8 @@ it('GET with callback must return 200 status error even if it is an error', func
error: [
'You are over platform\'s limits. Please contact us to know more details'
],
context: {
subtype: "datasource",
type: "limit"
}
context: "limit",
detail: "datasource"
});
done();

View File

@ -100,10 +100,8 @@ describe('timeout', function () {
error: [
'You are over platform\'s limits. Please contact us to know more details'
],
context: {
subtype: "datasource",
type: "limit"
}
context: "limit",
detail: "datasource"
});
done();
@ -184,10 +182,8 @@ describe('timeout', function () {
error: [
'You are over platform\'s limits. Please contact us to know more details'
],
context: {
subtype: "datasource",
type: "limit"
}
context: "limit",
detail: "datasource"
});
done();

View File

@ -50,6 +50,16 @@ function assertRequest (status, limit, remaining, reset, retry, done = null) {
assert.equal(res.headers['carto-rate-limit-reset'], reset);
assert.equal(res.headers['retry-after'], retry);
if(status === 429) {
const expectedResponse = {
error: ["You are over the limits."],
context: "limit",
detail: "rate-limit"
};
assert.deepEqual(JSON.parse(res.body), expectedResponse);
}
if (done) {
setTimeout(done, 1000);
}