why will method be executed when the previous method return a result?
See original GitHub issuewhen 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:
- Created 7 years ago
- Comments:9 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
because both your actions satisfy executed route.
when you access
user/allit satisfies for both/:idandall. How canidknow 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