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

TS error on use @HttpStatus() #315

Closed
archiii92 opened this issue Dec 20, 2017 · 4 comments
Closed

TS error on use @HttpStatus() #315

archiii92 opened this issue Dec 20, 2017 · 4 comments

Comments

@archiii92
Copy link

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Make simple nestjs project like in tutorial.
Take this example code.


import { Controller, Get, Post, HttpStatus } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @HttpStatus(204)
  @Post()
  create() {
    // TODO: Add some logic here
  }

  @Get()
  findAll() {
    return [];
  }
}

And get this error:

2

Expected behavior

Everithing is ok. Cause it in tutorial.

Minimal reproduction of the problem with instructions

Download nestjs starter project and copy-paste above controller's code.

What is the motivation / use case for changing the behavior?

Environment


Nest version: 4.5.1

For Tooling issues:
- Node version: 8.9.3   
- Platform:  Windows 10 

Others: VSCode

@shekohex
Copy link
Contributor

shekohex commented Dec 20, 2017

HttpStatus here. It's just a helper enum That have a lot of HTTP Status Codes, see this here

and I think what you are looking for is HttpCode(statusCode: number) see below

import { Controller, Get, Post, HttpStatus, HttpCode, HttpException } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @Post()
  @HttpCode(204)
  create() {
    // Add New Cat..
  }

  @Get()
  findAll() {
    return new HttpException('Nothing Here !', HttpStatus.NO_CONTENT);
  }
}

@archiii92
Copy link
Author

Yeap, just notice that ) Should fix - https://docs.nestjs.com/controllers . Tnx for help.

@pumano
Copy link
Contributor

pumano commented Dec 20, 2017

Example in docs contains @HttpStatus(200) while above example @HttpCode(...) Docs should be updated.

@lock
Copy link

lock bot commented Sep 25, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants