Hey there!
I’m using a Node+Mongoose backend as a REST API to my Ember app, and I have a model set up on the backend to ensure that the data exists where necessary, meets certain parameters, etc. Mongoose echoes out a handy error object in the event some of the data sent doesn’t fit the model, like this:
{ [ValidationError: Validation failed]
message: 'Validation failed',
name: 'ValidationError',
errors:
{ project:
{ [ValidatorError: project is required!]
message: 'project is required!',
name: 'ValidatorError',
path: 'project',
type: 'required',
value: undefined },
audience:
{ [ValidatorError: audience is required!]
message: 'audience is required!',
name: 'ValidatorError',
path: 'audience',
type: 'required',
value: undefined },
medium:
{ [ValidatorError: medium is required!]
message: 'medium is required!',
name: 'ValidatorError',
path: 'medium',
type: 'required',
value: undefined },
intent:
{ [ValidatorError: intent is required!]
message: 'intent is required!',
name: 'ValidatorError',
path: 'intent',
type: 'required',
value: undefined },
campaign:
{ [ValidatorError: campaign is required!]
message: 'campaign is required!',
name: 'ValidatorError',
path: 'campaign',
type: 'required',
value: undefined },
name:
{ [ValidatorError: name is required!]
message: 'name is required!',
name: 'ValidatorError',
path: 'name',
type: 'required',
value: undefined },
type:
{ [ValidatorError: type is required!]
message: 'type is required!',
name: 'ValidatorError',
path: 'type',
type: 'required',
value: null } } }
Since this is all in the error
object, Ember tries to stick this in it’s own data store using the error
model.
Is this an intelligent way of going about this? What’s the best way for me to make use of those errors and integrate them into an action (like one triggered after submitting a form)?
Thanks for any and all insight.