loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Question : how to change error message?

Open limichange opened this issue 12 years ago • 5 comments

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"
        ]
      }
    }
  }
}

limichange avatar Nov 17 '14 07:11 limichange

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

MartinCerny-awin avatar Aug 18 '16 23:08 MartinCerny-awin

I am also looking for the same thing.

vijay22sai avatar Nov 01 '16 06:11 vijay22sai

+1

matias-casal avatar Dec 31 '16 04:12 matias-casal

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);

shaheero avatar Apr 12 '17 03:04 shaheero

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..

febeks avatar Mar 15 '19 17:03 febeks