#Dynamic (method-logic-dependent) HTTP code without using underlying Response object?

1 messages · Page 1 of 1 (latest)

static hedge
#

Hello! I would like to know if it is possible to maintain the NestJS-esque way of returning an object directly in a controller method but at the same time specifying a different HTTP response code depending on method logic.

In other words, I want to know if there is a way to turn this:

res.status(variableAssignedInIfElse).json(payload);

Into:

return payload;```

As I am using TypeScript I really like the idea of controller methods returning objects instead of tinkering with the underlying transport.

Thanks!

Edit: The code below doesn't work as far as I have tested.

res.status(var);
return payload;

nocturne cargo
#

this is covered in the docs

#

you need to use the response object tho

#

another way would be moving that logic to an interceptor
so that you could avoid using the underlying response object
But then the controller will need to return the status alongside with the response data