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

docs(routing): add error handling section #2733

Merged
merged 2 commits into from
Sep 29, 2024

Conversation

horvbalint
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

While migrating some servers to Nitro (in Nuxt), I came across an odd behaviour that took some time to unveil. For some of the routes errors were handled correctly, while for others the client could not determine the error type. With some trial and error I figured out, that there is a difference between how an error is sent back to the client depening on which route directory the route is placed.

The routes/ dir uses a Content-Type of text/html, while the api/ dir application/json by default. In this PR I tried to clarify this in the docs, wich previously stated that the only difference is the /api/ prefix.

As a side note I would be very interested, in the reasoning behind this behaviour. I feel like it is quite footgun-y, while I don't see the benefits.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

docs/1.guide/2.routing.md Outdated Show resolved Hide resolved
docs/1.guide/0.index.md Outdated Show resolved Hide resolved
@horvbalint
Copy link
Contributor Author

@pi0 Thanks for the quick response! I went to sleep sorry πŸ˜ƒ

I tried to fix the docs according your comments. I found no appropriate place for this note in the current docs, so I created an 'Error handling' section in the routing guide (similar how it is in the H3 docs). Hopefully this is ok :)

Can you tell me the reasoning behind this route path based content type behaviour?

@horvbalint horvbalint changed the title docs: clarify the differences between the two route directories docs: error handling Sep 13, 2024
@horvbalint horvbalint requested a review from pi0 September 17, 2024 19:49
@pi0
Copy link
Member

pi0 commented Sep 29, 2024

Thanks again for the PR and sorry for my late reply.

The reason is that when using tools like curl or HTTP clients like fetch (instead of directly) making request, it is easier to inspect a json object instead.

For /api routes, and with higher order frameworks like Nuxt, it might make sense that we use HTML in browser at least. i belive this something doable in Nuxt (since it has it's own copy version of this)

@pi0 pi0 changed the title docs: error handling docs(routing): add error handling section Sep 29, 2024
@pi0 pi0 merged commit 8d1bad6 into nitrojs:v2 Sep 29, 2024
@pi0 pi0 mentioned this pull request Oct 31, 2024
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