0

I'm working on a project using EPF and having trouble when dealing with resources which fail with validation errors on the server.

I am creating a new user registration page, which takes an email address, login and password and asks the server to create a new user record via the REST API.

When validation fails the server returns a 422 with an errors hash in the JSON response.

First, I tried using the session.flush promise to get access to the response body:

registerNewUser: ->
  onSuccess = (models)=>
    newUser = @get('content')
    @transitionToRoute('user', newUser)
  onFailure = (response)->
    debugger
  @session.flush().then(onSuccess, onFailure)

The response argument passed to the decline action actually contains an Exception (in my case: "TypeError: Cannot call method 'toString' of undefined". Investigating the stack shows that it is an exception from deep within EPF - I'm pretty sure this is a bug, but I need to do more digging to confirm this.

"Okay," I thought. "I'll read the EPF source".

I came across https://github.com/GroupTalent/epf/blob/master/lib/rest/rest_adapter.js#L267 which appears to fire when the jQuery AJAX promise declines. It has a specific test for 422 and attempts to parse the JSON payload and attach it (along with a bunch of other useful information) to the model on the errors property. However, my newly-created user model has no errors property either.

Pretty much at a dead end for now. Does anyone know where I should be looking to make this work?

jamesotron
  • 65
  • 7
  • Can you post your model definitions? That error generally indicates that there is a bad type somewhere (e.g. `hasMany('posts')` or `hasMany('App.Post')` rather than the correct `hasMany('post')` or `hasMany(App.Post)` – ghempton Aug 19 '13 at 04:49
  • The app has only one model - so far. It's brand new. Here's the definitions: https://gist.github.com/jamesotron/6265891 – jamesotron Aug 19 '13 at 05:03

0 Answers0