Skip to content

Feature: Add response status to route object and plugins #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jhildenbiddle opened this issue Oct 31, 2023 · 0 comments · Fixed by #2253 or #2303
Closed

Feature: Add response status to route object and plugins #2294

jhildenbiddle opened this issue Oct 31, 2023 · 0 comments · Fixed by #2253 or #2303
Assignees

Comments

@jhildenbiddle
Copy link
Member

jhildenbiddle commented Oct 31, 2023

Feature request

  • Add response status to route object
  • Make response status available to plugin hooks
  • Identify and handle request errors properly (not just 404)

Problem or desire

  1. Internally, Docsify does not know response status details about the current route beyond basic success/error. This makes it difficult for contributors to handle various request errors properly.
  2. Externally, Docsify does not expose response status details to plugin authors. This makes it difficult fro plugin authors to handle various request errors properly.

As a result of the two issues above:

  1. Docsify incorrectly treats successful requests for empty markdown files as 404 errors. Docsify should handle empty pages properly and display an empty page as expected.
  2. Docsify assumes all failed requests are 404 errors and displays "404 - Not found" in the content area. This is misleading when requests fail for reasons other than a 404 error. Docsify should be able to identify and display all request error codes and status messages.

Proposal

Current route object:

{
  file: "README.md",
  path: "/",
  query: {}
}

Proposed route object:

// Success
{
  file: "README.md",
  path: "/",
  query: {},
  response: {
    ok: true,
    status: 200,
    statusText: "OK"
  }
}

// Failure
{
  file: "README.md",
  path: "/",
  query: {},
  response: {
    ok: false,
    status: 404,
    statusText: "Not Found"
  }
}

Plugin access:

window.$docsfy = {
  // ...
  plugins: [
    function(hook, vm) {
      hook.beforeEach(html => {
        console.log(vm.route.response.ok); // true
        console.log(vm.route.response.status); // 200
        console.log(vm.route.response.statusText); // "OK"
      }
    }
  ],
};

Implementation

See above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant