'Check ratelimit usage and set an error if necessary.'

def _check_usage(self, rate_limit):

    if rate_limit.check():
        return
    g.log.debug('rate-limiting    %s    with    %s    used', rate_limit.key, rate_limit.get_usage())
    if (self.error == errors.RATELIMIT):
        period_end = datetime.utcfromtimestamp(rate_limit.timeslice.end).replace(tzinfo=pytz.UTC)
        time = utils.timeuntil(period_end)
        self.set_error(errors.RATELIMIT, {'time': time}, field='ratelimit', code=429)
    else:
        self.set_error(self.error)
