Skip to content

Commit aebf47f

Browse files
authored
Handling ruleset limit exceeded error (#636)
1 parent 3eab019 commit aebf47f

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/security-rules/security-rules-api-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ interface Error {
250250
const ERROR_CODE_MAPPING: {[key: string]: SecurityRulesErrorCode} = {
251251
INVALID_ARGUMENT: 'invalid-argument',
252252
NOT_FOUND: 'not-found',
253+
RESOURCE_EXHAUSTED: 'resource-exhausted',
253254
UNAUTHENTICATED: 'authentication-error',
254255
UNKNOWN: 'unknown-error',
255256
};

src/security-rules/security-rules-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type SecurityRulesErrorCode =
2323
| 'invalid-argument'
2424
| 'invalid-server-response'
2525
| 'not-found'
26+
| 'resource-exhausted'
2627
| 'service-unavailable'
2728
| 'unknown-error';
2829

test/unit/security-rules/security-rules-api-client.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ describe('SecurityRulesApiClient', () => {
214214
.should.eventually.be.rejected.and.deep.equal(expected);
215215
});
216216

217+
it('should throw when the rulesets limit reached', () => {
218+
const resourceExhaustedError = {
219+
error: {
220+
code: 429,
221+
message: 'The maximum number of Rulesets (2500) have already been created for the project.',
222+
status: 'RESOURCE_EXHAUSTED',
223+
},
224+
};
225+
const stub = sinon
226+
.stub(HttpClient.prototype, 'send')
227+
.rejects(utils.errorFrom(resourceExhaustedError, 429));
228+
stubs.push(stub);
229+
const expected = new FirebaseSecurityRulesError('resource-exhausted', resourceExhaustedError.error.message);
230+
return apiClient.createRuleset(RULES_CONTENT)
231+
.should.eventually.be.rejected.and.deep.equal(expected);
232+
});
233+
217234
it('should throw unknown-error when error code is not present', () => {
218235
const stub = sinon
219236
.stub(HttpClient.prototype, 'send')

0 commit comments

Comments
 (0)