Skip to content

Commit 8bda07c

Browse files
committed
docs: document createError given error in arguments list
closes #45
1 parent 7b0ef2a commit 8bda07c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ var err = createError(404, 'This video does not exist!')
6363
- `message` - the message of the error, defaulting to node's text for that status code.
6464
- `properties` - custom properties to attach to the object
6565

66+
### createError([status], [error], [properties])
67+
68+
Extend the given `error` object with `createError.HttpError`
69+
properties. This will not alter the inheritance of the given
70+
`error` object, and the modified `error` object is the
71+
return value.
72+
73+
<!-- eslint-disable no-redeclare, no-undef, no-unused-vars -->
74+
75+
```js
76+
fs.readFile('foo.txt', function (err, buf) {
77+
if (err) {
78+
if (err.code === 'ENOENT') {
79+
var httpError = createError(404, err, { expose: false })
80+
} else {
81+
var httpError = createError(500, err)
82+
}
83+
}
84+
})
85+
```
86+
87+
- `status` - the status code as a number
88+
- `error` - the error object to extend
89+
- `properties` - custom properties to attach to the object
90+
6691
### new createError\[code || name\](\[msg]\))
6792

6893
Create a new error object with the given message `msg`.

0 commit comments

Comments
 (0)