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: handle empty json responses #473

Closed
wants to merge 1 commit into from

Conversation

jrebs
Copy link

@jrebs jrebs commented Sep 27, 2024

It is common to receive an HTTP 401 Unauthorized with an empty body when an API token is incorrect. While it's technically true that an empty string is not technically a valid JSON string, the result of this in rest.nvim is quite ungraceful. The user is given a huge messy error stack without any clear indication of what went wrong. And when the error message is closed by hitting enter, the results pane in rest.nvim is stuck in a "# Loading..." state and does not display the HTTP response code, making it very non-obvious what has gone wrong.

I reason that when this happens, it would be preferable to simply show the empty response and the 401 HTTP code because this is a preferable experience for the user. I'm very willing to believe there might be a more correct way to solve this problem, but this is what I came up with after a quick bit of wading around the codebase.

Below you can see the current user experience is versus what it looks like after the patch.

Before

image

image

After

image

@boltlessengineer
Copy link
Contributor

Thank you for your contribution. I didn't notice that case.

This seems to be an issue when neovim tries to run gq in empty buffer (normally vim does not work with empty buffer. It requires at least one line.)
So when utils.gq_lines receive empty table as lines, performing early return before even opening buffer with empty content will be enough.
I'll create a new PR instead of merging this.

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.

2 participants