Skip to content Skip to sidebar Skip to footer

How To Display Error Message In Ember Js 2.0

I would like to display an error message when the server responses with record not found. The model in the route handler: model: function(userLoginToken) { var userLoginToken=

Solution 1:

Ember depends on an DS.error object, in order to get errors from your models the response has to fulfill the requirements. In order to get Ember to recognize an valid error, in Ember 2.x the error code MUST be 422 and has to follow jsonapi http://jsonapi.org/format/#errors-processing

Solution 2:

If you want to catch the errors from the backend response you have to use the catch method:

this.store.findRecord('user-login-token', userLoginToken.get('mobileNumber'))
  .then(success => {
    // Do whatever you need when the response success
  })
  .catch(failure => {
    // Do whatever you need when the response fails
  })
},

For catching the errors automatically as you are doing in your template, your backend needs to response in the right way. I would suggest you to read the answer for this SO question.

Post a Comment for "How To Display Error Message In Ember Js 2.0"