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

Created on 17 Feb 2018  路  4Comments  路  Source: nestjs/nest

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}

type

Most helpful comment

Fixed in v4.6.4 馃檪

All 4 comments

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

I have this same problem

Fixed in v4.6.4 馃檪

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marshall007 picture marshall007  路  3Comments

breitsmiley picture breitsmiley  路  3Comments

rafal-rudnicki picture rafal-rudnicki  路  3Comments

JulianBiermann picture JulianBiermann  路  3Comments

thohoh picture thohoh  路  3Comments