docsifyjs / docsify

🃏 A magical documentation site generator.
https://docsify.js.org
MIT License
27.47k stars 5.67k forks source link

Feat: Improved error handling and response status availability #2303

Closed jhildenbiddle closed 10 months ago

jhildenbiddle commented 10 months ago

Summary

See #2294 for details.

Screenshots

Custom error handling via plugins (example)

CleanShot 2023-11-16 at 21 57 43@2x

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)

CleanShot 2023-11-16 at 19 03 25@2x

After: Displays accurate error information

CleanShot 2023-11-16 at 19 03 32@2x


Initial render with content load error

Before: No sidebar, plugins halted

CleanShot 2023-11-16 at 18 22 49@2x

After: Sidebar rendered, plugins complete

CleanShot 2023-11-16 at 18 22 56@2x


Rendering empty files/routes

Before: Empty files incorrectly treated as 404 errors

CleanShot 2023-11-16 at 19 10 49@2x

After: Empty files rendered properly

CleanShot 2023-11-16 at 19 11 01@2x


Related issue, if any:

2294

What kind of change does this PR introduce?

Feature

For any code change,

Does this PR introduce a breaking change?

No

Tested in the following browsers:

vercel[bot] commented 10 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 17, 2023 1:15am