Skip to content

Instantly share code, notes, and snippets.

@radixhound
Created July 1, 2011 07:30
Show Gist options
  • Save radixhound/1058044 to your computer and use it in GitHub Desktop.
Save radixhound/1058044 to your computer and use it in GitHub Desktop.
example of situation where our code blows up with mysql2 'connection is still waiting for a result' errors
class Authorization < Goliath::Synchrony::MongoReceiver
include Goliath::Validation
include Goliath::Rack::Validator
# time period to aggregate stats over, in seconds
class MissingApikeyError < BadRequestError ; end
class DatabaseSaveError < BadRequestError ; end
class RateLimitExceededError < ForbiddenError ; end
class UserIDMismatchError < UnauthorizedError ; end
# this is all pseud-code
def pre_process
mongodb_auth_lookup do |resp|
if resp
env['user_id'] = resp.user_id
end
end
end
def post_process
if body_has_a_object?
body[:object].save if env['user_id'] == body[:user_id]
end
#in reality we send a 401 if auth isn't valid or user_id mismatch
[status, headers, body]
end
end
class Users < Foodtree::API
class MissingUserIDError < BadRequestError ; end
def response(env)
resp = route_request #this will send PUT to update
resp
end
def update
if user = User.find(params[:id])
[200, {}, {:object => user, :user_id => user.id}]
else
raise MissingUserIDError
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment