Skip to content

Instantly share code, notes, and snippets.

@rafen
Last active August 29, 2015 13:58
Show Gist options
  • Save rafen/10027222 to your computer and use it in GitHub Desktop.
Save rafen/10027222 to your computer and use it in GitHub Desktop.
MMDBClient error debug for register_app
# Settings for local.py
#
# MMDB_API_HOST = 'http://mc.dev.nationalgeographic.com:8000'
#
# Load test database in your db. Use production db for this test if possible
# $ python manage.py loaddata mmdb/apps/users/fixtures/test_user.json
from mmdbcommons.client import MMDBClient, mmdb_client
from mmdbcommons.exceptions import AppAlreadyRegisteredError
# Create the client
client = MMDBClient(api_key='MMDB_DEBUG_KEY', api_user='memcen_debug')
try:
client.register_app(9617855, 'YourShot')
except (AppAlreadyRegisteredError, ):
print 'Ignored!'
@rafen
Copy link
Author

rafen commented Apr 7, 2014

Possible Solutions:

  1. Ask YourShot to hit the endpoint directly

  2. Modify the serializer error to raise ERROR_APP_ALREADY_REGISTERED instead of ERROR_DUPLICATE
    NOTE: this will require to update unit tests and membercenter code. MMDBClient will work as a result of the changes.

diff --git a/mmdb/apps/users/serializers.py b/mmdb/apps/users/serializers.py
index 19ba514..aaf0caf 100644
--- a/mmdb/apps/users/serializers.py
+++ b/mmdb/apps/users/serializers.py
@@ -354,8 +354,8 @@ class AppRegistrationSerializer(UserSubresourceSerializer, serializers.ModelSeri
     def save_object(self, obj, **kwargs):
         try:
             super(AppRegistrationSerializer, self).save_object(obj, **kwargs)
-        except IntegrityError as e:
-            raise self.context['view'].MMDBApiError(mmdbstatus.ERROR_DUPLICATE, 403)
+        except IntegrityError:
+            raise self.context['view'].MMDBApiError(mmdbstatus.ERROR_APP_ALREADY_REGISTERED, 403)


 class UserInterestsSerializer(UserSubresourceSerializer, serializers.ModelSerializer):

@rafen
Copy link
Author

rafen commented Apr 8, 2014

If you need option 1) see the this snippet as an example of how to do it:

https://gist.github.com/rafen/10145434

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment