OxPenguin
OxPenguin

Reputation: 101

Nest JS on Cloud function not sending out HTTP error message

I have a NestJS application controller. In this controller if something goes wrong i would like to send back a 500 error with a custom "errorRespose" message (string).

The application is running on a GCP Cloud Function.

Everything works fine, except when the application sends out the 500 error this just arrives to the client with "Internal Server error" message and not with the one i have set (which contains additional informations on what went wrong).

From the docs I understand we only need to throw an HttpException, but this just doesn't seem to work in my case and I can't figure out why.

I made the example on a single controller but this happens all over the application.

Here the code:

@Post('marketData')
async getMarketData(@Body() body) {
    let errorResponse = error_messages.PROCESS_FAIL;

    try {
        .... some logics
        return someData;
    } catch (err) {
        this.logger.warn(err);
        errorResponse = err;
    }

    throw new HttpException(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}

NestJS versions are:

"@nestjs/common": "^10.3.1",
"@nestjs/core": "^10.3.1",
"@nestjs/platform-express": "^10.3.1",
"@nestjs/swagger": "^7.2.0",

Upvotes: 0

Views: 123

Answers (0)

Related Questions