Coder Social home page Coder Social logo

Comments (9)

pleerock avatar pleerock commented on May 8, 2024 2

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

from routing-controllers.

Diluka avatar Diluka commented on May 8, 2024 2

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.

from routing-controllers.

lp6moon avatar lp6moon commented on May 8, 2024

I know both of them match the path, but when the first returned why the second still process.

here is my error print:

getOne
getAll
[2016-08-17 14:34:15.362] [ERROR] app.js - Promise没有拒绝处理函数:  Promise {
  <rejected> Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
    at ServerResponse.header (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:719:10)
    at ServerResponse.json (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:247:10)
    at ExpressDriver.handleError (D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\driver\ExpressDriver.js:248:22)
    at D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\RoutingControllerExecutor.js:110:67
    at process._tickCallback (internal/process/next_tick.js:103:7) }  原因:  Error: Can't set headers after they are sent.
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
    at ServerResponse.header (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:719:10)
    at ServerResponse.json (D:\Workspace\ProjectSpace\lp-test\node_modules\express\lib\response.js:247:10)
    at ExpressDriver.handleError (D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\driver\ExpressDriver.js:248:22)
    at D:\Workspace\ProjectSpace\lp-test\node_modules\routing-controllers\RoutingControllerExecutor.js:110:67
    at process._tickCallback (internal/process/next_tick.js:103:7)

from routing-controllers.

pleerock avatar pleerock commented on May 8, 2024

Because there is no logic that prevents execution of the second action if first returned something. Not sure if it should be there.

In your case you should have proper defined routes

from routing-controllers.

Diluka avatar Diluka commented on May 8, 2024

In your framework

                if (action.isJsonTyped) {
                    response.json(result);
                }
                else {
                    response.send(String(result));
                }
                options.next();

why call next() after response.send()? Doing so will cause error

from routing-controllers.

pleerock avatar pleerock commented on May 8, 2024

because there can be a middleware that should be called after route execution (for example middleware that logs number of seconds spent on loading). Without calling next() it will not execute such middlewares

from routing-controllers.

Diluka avatar Diluka commented on May 8, 2024

And there can be some middlewares just deal with errors like 404 NOT FOUND. Like this, the middleware is always do the error handle, although there is no error need to be handled

from routing-controllers.

pleerock avatar pleerock commented on May 8, 2024

didnt get what you mean. Error handlers works different way, for error middleware you call next(err) and thats is called only when error occur, not always like in this case

from routing-controllers.

github-actions avatar github-actions commented on May 8, 2024

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

from routing-controllers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.