Skip to content

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

@jhildenbiddle

Description

@jhildenbiddle

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions