mysociety / popit-api

DEPRECATED - Development on PopIt has stopped and it is no longer being maintained
https://goo.gl/Vvej4Q
Other
17 stars 3 forks source link

has the structure of E11000 error responses changed? #113

Open mhl opened 9 years ago

mhl commented 9 years ago

I have code that uses the PopIt API that I'm sure used to work along these lines:

try:
    self.api.organizations.post(party_data)
    print "NEW"
except HttpServerError as e:
    error = json.loads(e.content)
    if error.get('error', {}).get('code') == 11000:
        print "DUPLICATE"

... but which no longer works - the error content now looks like:

{
    "errors": [
        "Something went wrong", 
        "E11000 duplicate key error index: popitdev_candidates-posts_20141217230331.organizations.$_id_  dup key: { : \"party:141\" }"
    ]
}

i.e. there's no error element (only errors), and there's no code element anywhere in the content. If I'm not completely losing it (quite possible) this is an unadvertised breaking API change

chrismytton commented 9 years ago

I think this change in API behaviour must have been caused by https://github.com/mysociety/popit-api/commit/5b4555ea4eae8b9c7f6cfb02be49204ecc8b7921, but I'm not entirely sure I understand how the previous behaviour was occurring. I'll have to dig into this a bit more to understand what's happened and get a fix in place.

chrismytton commented 9 years ago

As an aside, the documentation only mentions the errors property on responses, so this is at least as advertised, I guess :) http://popit.poplus.org/docs/api/reference/#errors