Loopback: Question : how to change error message?

Created on 17 Nov 2014  路  5Comments  路  Source: strongloop/loopback

from

{
  "error": {
    "name": "ValidationError",
    "status": 422,
    "message": "The `User` instance is not valid. Details: `password` can't be blank.",
    "statusCode": 422,
    "details": {
      "context": "User",
      "codes": {
        "password": [
          "presence"
        ]
      },
      "messages": {
        "password": [
          "can't be blank"
        ]
      }
    }
  }
}

to

{
  "error": {
    "name": "ValidationError",
    "status": 422,
    "message": "Password can't be blank.",
    "statusCode": 422,
    "details": {
      "context": "User",
      "codes": {
        "password": [
          "presence"
        ]
      },
      "messages": {
        "password": [
          "Password can't be blank"
        ]
      }
    }
  }
}

Most helpful comment

Have you found the solution? I am looking exactly for the same thing.

All 5 comments

Have you found the solution? I am looking exactly for the same thing.

I am also looking for the same thing.

+1

In the .js files (not .json) of the models, have if conditions, and in the else part:

var error = new Error('Your custom error message.');
error.status = 403; //your desired code
next(error);

is this the only solution? hard code it? Cant believe loopback is so complex and the most important things are left out to be changed manually...insane..

Was this page helpful?
0 / 5 - 0 ratings