Nest: HTTP exceptions body

Created on 15 Mar 2020  路  2Comments  路  Source: nestjs/nest

Regression

Sorry @kamilmysliwiec but this behavior of breaking changes is for me unacceptable.

For code like:

throw new ForbiddenException('Forbidden resource');

It was smth like:

{
  "statusCode": 403,
  "message": "Forbidden resource"
}

But now it change from a "message" to a "error" key, as:

{
  "statusCode": 403,
  "message": "Forbidden",
  "error": "Forbidden resource"
}

Like why? Why did you change a message key to an error? This is misleading, from the beginning of javascript life, Error object at the first constructor parameter take a message, and now it's changed to an error key?!

This is kind of reinventing the wheel?

Potential Commit/PR that introduced the regression**

I do not have any commit or pr for this.

Describe the regression

Described at the first paragraph.

Input Code

Code at the first paragraph.

Expected behavior/code

I would love to have as it was, message key from a constructor should be a message in error response. If not, then I will have to rebuilt a lot of applications, or override a default error handler for no good reason.

Environment


Nest version: 7.0.0

For Tooling issues:
- Node version: v12.13.1  
- Platform: Linux  

Others:

needs triage type

Most helpful comment

PR https://github.com/nestjs/nest/pull/4045
Related:

However, you're right - the order of parameters is wrong. The first argument should be used for message key of Error object, and thus (again, for the sake of consistency), for the response object. When not passed, the constructor should fallback to a generic message. Fixed in 7.0.2, will update docs asap

All 2 comments

PR https://github.com/nestjs/nest/pull/4045
Related:

However, you're right - the order of parameters is wrong. The first argument should be used for message key of Error object, and thus (again, for the sake of consistency), for the response object. When not passed, the constructor should fallback to a generic message. Fixed in 7.0.2, will update docs asap

Thank you @kamilmysliwiec <3

Was this page helpful?
0 / 5 - 0 ratings

Related issues

2233322 picture 2233322  路  3Comments

KamGor picture KamGor  路  3Comments

tronginc picture tronginc  路  3Comments

anyx picture anyx  路  3Comments

breitsmiley picture breitsmiley  路  3Comments