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: recommend .end instead of .send when no body is being sent #33611

Merged
merged 2 commits into from Feb 3, 2022

Conversation

balazsorban44
Copy link
Member

Fixes #33536

I was thinking to make body optional here instead:

type Send<T> = (body: T) => void

But that might result in more errors when not setting the status code correctly. So it's the easiest for us to just recommend .end() which .send() uses when there is no argument.

if (body === null || body === undefined) {

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running yarn lint

@johannpinson
Copy link

Maybe it's need an update on the fix explanation because it's still about "send an empty body".

And can the .end() function may be documented on the API Routes page? (or not because it's a native node method).

@kodiakhq kodiakhq bot merged commit b772513 into canary Feb 3, 2022
@kodiakhq kodiakhq bot deleted the docs/empty-body-res-end branch February 3, 2022 02:41
natew pushed a commit to natew/next.js that referenced this pull request Feb 16, 2022
…ercel#33611)

Fixes vercel#33536

I was thinking to make `body` optional here instead:

https://github.com/vercel/next.js/blob/2c6bd1ed1b3821debda74dc8f407b8f11779a4f0/packages/next/shared/lib/utils.ts#L262

But that might result in more errors when not setting the status code correctly. So it's the easiest for us to just recommend `.end()` which `.send()` uses when there is no argument.

https://github.com/vercel/next.js/blob/c71465d87a7eeb050e5cc7e94817f19e69e9d1e4/packages/next/server/api-utils.ts#L269

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Routes 204 > Conflict between TypeScript and linter rules
3 participants