Skip to content

Commit 93dc5df

Browse files
committed
Add too many requests error
1 parent 97583e3 commit 93dc5df

File tree

6 files changed

+45
-0
lines changed

6 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Below is the list of all available errors:
4242
| GoneError | 410 | Gone |
4343
| NotFoundError | 404 | Not Found |
4444
| ServiceUnavailableError | 503 | Service Unavailable |
45+
| TooManyRequestsError | 429 | Too Many Requests |
4546
| UnauthorizedError | 401 | Unauthorized |
4647
| ValidationFailedError | 400 | Validation Failed |
4748

src/errors/too-many-requests-error.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
const HttpError = require('./http-error');
8+
9+
/**
10+
* Export "Too Many Requests" error.
11+
*/
12+
13+
module.exports = class TooManyRequestsError extends HttpError {
14+
/**
15+
* Constructor.
16+
*/
17+
18+
constructor() {
19+
super(429, ...arguments);
20+
}
21+
};

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
HttpError: require('./errors/http-error'),
1414
NotFoundError: require('./errors/not-found-error'),
1515
ServiceUnavailableError: require('./errors/service-unavailable-error'),
16+
TooManyRequestsError: require('./errors/too-many-requests-error'),
1617
UnauthorizedError: require('./errors/unauthorized-error'),
1718
ValidationFailedError: require('./errors/validation-failed-error')
1819
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
const { TooManyRequestsError } = require('../../src');
8+
const test = require('../utils/test-http-error');
9+
10+
/**
11+
* Test "TooManyRequestsError" error.
12+
*/
13+
14+
describe('TooManyRequestsError', () => {
15+
test(TooManyRequestsError, 429, 'Too Many Requests');
16+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { HttpError } from './http-error';
2+
export declare class TooManyRequestsError extends HttpError {
3+
constructor(message?: string, props?: object);
4+
constructor(props?: object);
5+
}

types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export * from './errors/gone-error';
66
export * from './errors/http-error';
77
export * from './errors/not-found-error';
88
export * from './errors/service-unavailable-error';
9+
export * from './errors/too-many-requests-error';
910
export * from './errors/unauthorized-error';
1011
export * from './errors/validation-failed-error';

0 commit comments

Comments
 (0)