Skip to content
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

fix: invalid username or repos, timeout error #22 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

klee214
Copy link

@klee214 klee214 commented Oct 15, 2020

Fixes #22 I put the axios request in the try catch block, so if the username or repos name is invalid, it will simply go catch block then finish the getReadme() function. So far, when users put wrong names, it will just normal 'cannot get message'.

I don't know how to specifically do i need to change for this (either simply redirect to the home page or make a 404 page), so please let me know if there is anything I can help more!!

Copy link
Owner

@aemmadi aemmadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change! This solves the application crashing issue, but users are now presented with a Cannot GET /docs/:user/:repo text. This is the default http error when trying to GET something that doesn't exist.

If you can, try to redirect to a 404 page so it doesn't disturb the user experience as much!

EDIT: Follow this and edit the $window.docsify object in the /docs/index.html file. Make a 404.md in the docs/ folder. That should work, let me know if you have any trouble!

@klee214
Copy link
Author

klee214 commented Oct 15, 2020

Sure! I will give it a shot!

@klee214
Copy link
Author

klee214 commented Oct 15, 2020

Hi again, regarding this issue, I have realized something. Because we redirect to the certain URL res.redirect('/docs/${user}/${repo}/'); if the URL doesn't exist no matter what we have in my404.md, it doesn't shows. I have tried 2 different ways, one is use res.sendFile('index.html') when username or repo is invalid.

if(user && repo){
      res.redirect(`/docs/${user}/${repo}/`);
    }else{
      res.sendFile(path.resolve(__dirname, './docs/index.html'));
    }

In this case, we can show empty website with 404-page error message(I don't know where the error message came from) -cannot use notFoundPage: my404.md -. In this case, we need to make a proper 404 error page with html and send the static file when we come across the 404 error.

if(user && repo){
      res.redirect(`/docs/${user}/${repo}/`);
    }else{
      res.sendFile(path.resolve(__dirname, './docs/404page.html')); // like this
    }

Another is we can add notFoundPage: my404.md for every generateHtmlWithConfig() however in this case if the user or repo is invalid no data there. So we cannot make _doc directory properly. So it may require a lot changes on the program.
I suggest the first approach because it is simple and doesn't require a lot changes.
Please let me know if there is another way to fix it!!!!
I am not expert about docsify, so there should be better way I believe!!!

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

Successfully merging this pull request may close these issues.

Application crashes at invalid endpoint
2 participants