Skip to content

Commit da58c8b

Browse files
author
Matt Broadstone
committed
doc(errors): update docs related to throwing errors
The documentation was not clear that epilogue specific errors need to be imported before being used.
1 parent 17b5e64 commit da58c8b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ Controller actions in turn have hooks for setting and overriding behavior at eac
6464
We have these milestones to work with: `start`, `auth`, `fetch`, `data`, `write`, `send`, and `complete`.
6565

6666
```javascript
67+
var ForbiddenError = require('epilogue').Errors.ForbiddenError;
68+
6769
// disallow deletes on users
6870
users.delete.auth(function(req, res, context) {
6971
throw new ForbiddenError("can't delete a user");
72+
// optionally:
73+
// return context.error(403, "can't delete a user");
7074
})
7175
```
7276

@@ -153,6 +157,8 @@ module.exports = {
153157
To show an error and halt execution of milestone functions you can throw an error:
154158

155159
```javascript
160+
var ForbiddenError = require('epilogue').Errors.ForbiddenError;
161+
156162
before: function(req, res, context) {
157163
return authenticate.then(function(authed) {
158164
if(!authed) throw new ForbiddenError();

docs/Milestones.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ users.list.fetch.before(function(req, res, context) {
9494
});
9595

9696
// example for 2 and 4
97+
var ForbiddenError = require('epilogue').Errors.ForbiddenError;
98+
9799
users.list.fetch.before(function(req, res, context) {
98100
return checkLoggedIn(function(loggedIn) {
99101
if(!loggedIn) {
@@ -234,4 +236,4 @@ The default implementation is to do the following:
234236

235237
All Sequelize ValidationError objects are wrapped in a BadRequestError and are accessed on error.cause.
236238
Any EpilogueError object are passed as-is and any other errors are wrapped in an EpilogueError and can be accessed on
237-
error.cause
239+
error.cause

0 commit comments

Comments
 (0)