Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created January 13, 2013 21:38
Show Gist options
  • Save shreyansb/4526331 to your computer and use it in GitHub Desktop.
Save shreyansb/4526331 to your computer and use it in GitHub Desktop.
#golang style errors in python. like it so far.
@app.route("/<user_id>/facebook_id", methods=["PUT"])
def put_facebook_id(user_id):
fb_d, err = get_facebook_data_from_cookie(request)
if err:
return json_error(err)
else:
# save and return success
pass
def get_facebook_data_from_cookie(request):
c_name = "fbsr_%s" % settings.FACEBOOK_APP_ID
c = request.cookies.get(c_name)
if not c:
return {}, "no facebook cookie in request"
d, err = validate_signed_request(c)
if err:
return {}, "invalid facebook signed_request"
else:
return d, None
def json_error(msg):
return json.dumps({'error': msg}), 400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment