Skip to content

Commit

Permalink
Add 402 payment required (#130)
Browse files Browse the repository at this point in the history
Closes #128
  • Loading branch information
alanshaw authored and arb committed Sep 27, 2016
1 parent 6c46048 commit d2d5419
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ Generates the following response:
}
```

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

Returns a 402 Payment Required error where:
- `message` - optional message.
- `data` - optional additional error data.

```js
Boom.paymentRequired('bandwidth used');
```

Generates the following response payload:

```json
{
"statusCode": 402,
"error": "Payment Required",
"message": "bandwidth used"
}
```

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

Returns a 403 Forbidden 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 @@ -220,6 +220,12 @@ exports.unauthorized = function (message, scheme, attributes) { // Or f
};


exports.paymentRequired = function (message, data) {

return internals.create(402, message, data, exports.paymentRequired);
};


exports.forbidden = function (message, data) {

return internals.create(403, message, data, exports.forbidden);
Expand Down
22 changes: 22 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@ describe('unauthorized()', () => {
});


describe('paymentRequired()', () => {

it('returns a 402 error statusCode', (done) => {

expect(Boom.paymentRequired().output.statusCode).to.equal(402);
done();
});

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

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

it('sets the message to HTTP status if none provided', (done) => {

expect(Boom.paymentRequired().message).to.equal('Payment Required');
done();
});
});


describe('methodNotAllowed()', () => {

it('returns a 405 error statusCode', (done) => {
Expand Down

0 comments on commit d2d5419

Please sign in to comment.