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

What's "supposed" to happen when status is error? #313

Open
eggmatters opened this issue Jan 12, 2015 · 1 comment
Open

What's "supposed" to happen when status is error? #313

eggmatters opened this issue Jan 12, 2015 · 1 comment

Comments

@eggmatters
Copy link

I make a call to retrieve a model from an api. The call fails validation and returns a 422 (Unprocessable Entity). The body of the response is an array of arrays, with key value pairs for the attribute and associated error:

[["username", "has already been taken"]]

It's ugly and her/model/orm.rb throws a "no implicit conversion of Symbol into Integer" exception. Which I get, but the above constrruct was generated by Active Record (albeit rails 1.4).

I can create a hash of those kv pairs, but then, Her merely assigns them as valid attributes and my controller receives a valid 200 response. What happened to the error status? Is there any hidden documentation about how Her handles error responses?

@hubert
Copy link
Contributor

hubert commented Mar 31, 2015

Hi @eggmatters. Which middleware are you using to parse the responses you get back from the API you're calling? Based on your description of the behavior, I'd guess you're using Her::Middleware::FirstLevelParseJSON (same as DefaultParseJSON).

If that's the case, Her will expect a hash of the model's attributes at the top level, including errors. so something like:

{ 
  "username": "eggmatters",
  "email": "eggmatters@github.com",
  "errors": { "username": ["has already been taken"] }
}

there's also some examples in the middleware specs.

hope that helps!

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

2 participants