[cli] Render an error page when middleware explodes. (#6934)

### Related Issues

This adds error handling for middleware in `vc dev`

Local looks a little different than production:
Local
![image](https://user-images.githubusercontent.com/4172067/139951848-efa08a88-aeee-446f-8319-35c8bb0b1d75.png)

Production
![image](https://user-images.githubusercontent.com/4172067/139951580-33a4ad0f-18a5-4aa1-bfb0-5e1da646a4b8.png)


### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [ ] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
This commit is contained in:
Gary Borton
2021-11-02 16:57:46 -07:00
committed by GitHub
parent 2e69f2513d
commit 8714f1905e
4 changed files with 26 additions and 11 deletions

View File

@@ -1421,6 +1421,16 @@ export default class DevServer {
const middlewareResult = await runDevMiddleware(req, res, this.cwd);
if (middlewareResult) {
if (middlewareResult.error) {
this.sendError(
req,
res,
requestId,
'EDGE_FUNCTION_INVOCATION_FAILED',
500
);
return;
}
if (middlewareResult.finished) {
return;
}