Feat: Improved error handling and response status availability by jhildenbiddle · Pull Request #2303 · docsifyjs/docsify
Summary
- Add response status to internal route object
- Expose response status to plugin hooks to allow for custom error handling.
- Update default error page content with error status and status text (e.g. "401 - Not Authorized", "500 - Internal Server Error", etc.) instead of displaying "404 - Not Found" for all errors.
- Fix issue where initial site render was incomplete when content fetch failed (e.g., no sidebar, plugins halted, etc.)
- Fix issue where empty markdown pages/routes were handled as 404 errors.
- Add tests to verify default error handling
- Add tests to verify
notFoundPageerror handling - Add tests to verify response data availability via plugins
See #2294 for details.
Screenshots
Custom error handling via plugins (example)
window.$docsify = { // ... plugins: [ function (hook, vm) { hook.beforeEach(html => { const { file, response } = vm.route; const { ok, status, statusText } = response; if (ok === false) { return [ `# Oops!`, `A **${status} - ${statusText}** error occurred while requesting **${vm.route.file}**`, ].join('\n\n'); } }); }, ], }
Default error content updates (500 error)
Before: Displays inaccurate error information (shows 404 but should be 500)
After: Displays accurate error information
Initial render with content load error
Before: No sidebar, plugins halted
After: Sidebar rendered, plugins complete
Rendering empty files/routes
Before: Empty files incorrectly treated as 404 errors
After: Empty files rendered properly
Related issue, if any:
What kind of change does this PR introduce?
Feature
For any code change,
- Related tests have been added or updated, if needed
Does this PR introduce a breaking change?
No
Tested in the following browsers:
- Chrome
- Firefox
- Safari
- Edge






