Skip to content

Commit 829ba0d

Browse files
authored
feat: add forwardError option to README with usage example
1 parent 215a71c commit 829ba0d

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ See [below](#other-servers) for an example of use with fastify.
7979
| **[`writeToDisk`](#writetodisk)** | `boolean\|Function` | `false` | Instructs the module to write files to the configured location on disk as specified in your `webpack` configuration. |
8080
| **[`outputFileSystem`](#outputfilesystem)** | `Object` | [`memfs`](https://github.com/streamich/memfs) | Set the default file system which will be used by webpack as primary destination of generated files. |
8181
| **[`modifyResponseData`](#modifyresponsedata)** | `Function` | `undefined` | Allows to set up a callback to change the response data. |
82+
| **[`forwardError`](#forwarderror)** | `boolean` | `false` | Enable or disable forwarding errors to the next middleware. |
8283

8384
The middleware accepts an `options` Object. The following is a property reference for the Object.
8485

@@ -476,6 +477,35 @@ instance.waitUntilValid(() => {
476477
});
477478
```
478479

480+
### `forwardError`
481+
482+
Type: `boolean`
483+
Default: `false`
484+
485+
Enable or disable forwarding errors to the next middleware. If `true`, errors will be forwarded to the next middleware, otherwise, they will be handled by `webpack-dev-middleware` and a response will be handled case by case.
486+
487+
This option don't work with hono, koa and hapi, because of the differences in error handling between these frameworks and express.
488+
489+
```js
490+
const express = require("express");
491+
const webpack = require("webpack");
492+
const middleware = require("webpack-dev-middleware");
493+
494+
const compiler = webpack({
495+
/* Webpack configuration */
496+
});
497+
498+
const instance = middleware(compiler, { forwardError: true });
499+
500+
const app = express();
501+
app.use(instance);
502+
503+
app.use((err, req, res, next) => {
504+
console.log(`Error: ${err}`);
505+
res.status(500).send("Something broke!");
506+
});
507+
```
508+
479509
## FAQ
480510

481511
### Avoid blocking requests to non-webpack resources.

0 commit comments

Comments
 (0)