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

Exception thrown or passed in the done function of a middleware ends up to "[object Object]" #431

Closed
bojidaryovchev opened this issue Feb 17, 2018 · 4 comments
Assignees

Comments

@bojidaryovchev
Copy link

I'm submitting a...

[ ] Regression

Current behavior

Let's say we got a consumer which applies middleware X for certain routes.. If we throw an exception in that middleware X (or pass the exception in the next/done function as new SampleException(...)), we receive a response of "[object Object]" which is really strange..

Expected behavior

@nestjs/common 4.5.9, @nestjs/core 4.5.10, @nestjs/microservices 4.5.8, @nestjs/testing 4.5.5, @nestjs/websockets 4.5.8 => with these versions it works properly - instead of "[object Object]", the proper exception is returned

Minimal reproduction of the problem with instructions

@controller('api')
export class SampleController {
@get('something')
getSomething() {}
}

const middleware = (req: Request, res: Response, next: NextFunction) => {
next(new UnauthorizedException('Invalid credentials'));
}

@module({
controllers: [SampleController]
})
export class SampleModule {
configure(consumer: MiddlewaresConsumer) {
consumer.apply(middleware).forRoutes({path: 'api/getSomething', method: RequestMethod.Get})
}
}

Current behaviour:
GET /api/getSomething => [object Object] // [object Object] also gets logged in the server console

Expected behaviour (how it used to work):
GET /api/getSomething => {error: 'Unauthorized', message: 'Invalid credentials', status: 401}

@bojidaryovchev
Copy link
Author

the issue comes from the @nestjs/core package (I tested it by using an older @nestjs/core package and it worked)

@cdiaz
Copy link

cdiaz commented Feb 18, 2018

I have this same problem

@kamilmysliwiec
Copy link
Member

Fixed in v4.6.4 🙂

@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.
Projects
None yet
Development

No branches or pull requests

3 participants