What's "supposed" to happen when status is error?
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?
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": "[email protected]",
"errors": { "username": ["has already been taken"] }
}
there's also some examples in the middleware specs.
hope that helps!