Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Request was malformed' on POST, error is hard to track down in the code #41

Closed
jasonrhodes opened this issue Jan 11, 2014 · 5 comments
Closed

Comments

@jasonrhodes
Copy link

Just trying to get fortune up and running with a simple test, with this:

var fortune = require('fortune');

fortune()
  .resource('book', {
    title: String
  })
  .listen('3000');

Which is working fine listening, and /books returns { "books": [ ] } as expected. But when I try to POST to create a new book, like this:

$ curl -X POST -H "Content-Type: application/json" -d '{"title":"A Storm of Swords"}' http://localhost:3000/books

I get the following, somewhat unspecific error.

{
  "error": "Request was malformed.",
  "detail": "TypeError: Cannot call method 'forEach' of undefined"
}
  1. It would be nice if that error was a little more specific, or gave me some way to track down where it came from. Even a search through my entire app for "Cannot call method" returns no results so I'm having trouble tracking it down.
  2. Is this an error in my POST request or a bug in the library?

Thanks!

@jasonrhodes
Copy link
Author

OK so if I had remembered to check the nodemon output, I would've found the stack trace a lot sooner (duh). Closing this because the error isn't hard to find, really.

Related: The way Fortune requires POST requests to be formatted is really strange and unintuitive to me, but it looks like that's hwo the json-api.org format is set up. Reference: json-api/json-api#131

@gr0uch
Copy link
Member

gr0uch commented Jan 12, 2014

Yep, the format is somewhat unwieldy. Actually I was thinking of relaxing this requirement of wrapping the posted resource if it is singular, but I'm not sure what @steveklabnik would think.

@steveklabnik
Copy link

We actually also break this rule at Balanced right now. I like the 'always multiple' because it simplifies processing. I think it's a semi-ambiguous part of the spec, but I'd like for it to be not so.

@cgrossde
Copy link

It seems the spec changed and now single objects are a must: http://jsonapi.org/format/#crud-creating-individual-resources
I just spent half an hour figuring out why my post failed -.-
@daliwali Please add a hint in your docs that posting only accepts an array and not a single object or drop me a line and I will write a pull-request.

@gr0uch
Copy link
Member

gr0uch commented Sep 20, 2014

@cgrossde currently doing a rewrite of the entire thing, decoupling fortune from specific formats such as JSON API, but it will still be supported as the default format. Seems like there are breaking changes due to the spec changing, so I'd like to distance those problems from this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants