Skip to content

Commit

Permalink
Support Precondition Required
Browse files Browse the repository at this point in the history
Closes #74
  • Loading branch information
Mike Atkins committed Oct 21, 2015
1 parent a9730fd commit ab84618
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,26 @@ Generates the following response payload:
}
```

### `Boom.preconditionRequired([message], [data])`

Returns a 428 Precondition Required error where:
- `message` - optional message.
- `data` - optional additional error data.

```js
Boom.preconditionRequired('you must supply an If-Match header');
```

Generates the following response payload:

```json
{
"statusCode": 428,
"error": "Precondition Required",
"message": "you must supply an If-Match header"
}
```

### `Boom.tooManyRequests([message], [data])`

Returns a 429 Too Many Requests error where:
Expand Down
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ exports.badData = function (message, data) {
};


exports.preconditionRequired = function (message, data) {

return internals.create(428, message, data, exports.preconditionRequired);
};


exports.tooManyRequests = function (message, data) {

return internals.create(429, message, data, exports.tooManyRequests);
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@ describe('badData()', function () {
});


describe('preconditionRequired()', function () {

it('returns a 428 error statusCode', function (done) {

expect(Boom.preconditionRequired().output.statusCode).to.equal(428);
done();
});

it('sets the message with the passed in message', function (done) {

expect(Boom.preconditionRequired('my message').message).to.equal('my message');
done();
});
});


describe('tooManyRequests()', function () {

it('returns a 429 error statusCode', function (done) {
Expand Down

0 comments on commit ab84618

Please # to comment.