question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

why will method be executed when the previous method return a result?

See original GitHub issue

when I visit: http://localhost:3000/api/user/all?id=123 the result is ‘{“id”:“all”,“flag”:“getOne”}’,but there is a Error: Can’t set headers after they are sent. why will Method:getAll be executed when Method:getOne return a result?

import {Controller, JsonResponse, Param, Get, QueryParam} from "routing-controllers";

@Controller('/user')
export class UserController {

    @Get("/:id")
    @JsonResponse()
    getOne(@Param("id") id:string) {
        console.log('getOne');
        return {id:id,flag:'getOne'};
    }

    @Get("/all")
    getAll(@QueryParam("id") id:number) {
        console.log('getAll');
        return {id:id,flag:'getAll'};
    }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Dilukacommented, Aug 17, 2016

Now, I understand the design. thx I previously use express not in the proper way. It needs to execute middlewares in the both sides of route.

2reactions
pleerockcommented, Aug 17, 2016

because both your actions satisfy executed route.

when you access user/all it satisfies for both /:id and all. How can id know if your “all” isn’t id?

You can solve it either by using another route for all, either to specify regexp to “id” what it can be, and what it can’t. For example: /users/:id(\\d+)" if id can be only a number

Read more comments on GitHub >

github_iconTop Results From Across the Web

Result of a method: the return statement
When the return statement is executed inside a method it causes the termination of the method and it returns its result to the...
Read more >
Does a return statement end a method? - java - Stack Overflow
Once the return is executed, the rest of the code in the method won't be executed and control will be passed to the...
Read more >
Will a finally block execute after a return statement in a method ...
Yes, the finally block will be executed even after a return statement in a method. The finally block will always execute even an...
Read more >
Returning a Result from a Method
This way the method will stop its execution without returning a value, and after it there shouldn't be an expression, which should be...
Read more >
return - JavaScript - MDN Web Docs - Mozilla
The return statement ends function execution and specifies a value to be returned to the function caller.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found