~osomon/moovida/account_admin

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/account/resource_provider.py

  • Committer: Olivier Tilloy
  • Date: 2009-09-09 10:17:40 UTC
  • mfrom: (1498.3.43 resource_provider)
  • Revision ID: olivier@fluendo.com-20090909101740-wpdqtxgs6v0v3f1t
Merged the latest resource provider branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    provider = manager.get_resource_provider_by_path(provider_path)
59
59
    return provider
60
60
 
 
61
class APIResponseError(Exception):
 
62
    """ Exception enclosing an error model returned by the WebService API.
 
63
 
 
64
    @ivar error_model: server-side error model
 
65
    @type error_model: L{elisa.plugins.account.models.ErrorModel}
 
66
    """
 
67
 
 
68
    def __init__(self, error_model):
 
69
        super(APIResponseError, self).__init__()
 
70
        self.error_model = error_model
61
71
 
62
72
class AccountsResourceProvider(ResourceProvider):
63
73
    """
409
419
            attr_name = "error_model"
410
420
 
411
421
        self.log("response for uri: %r ... data: %r", uri, response)
412
 
        if log.getCategoryLevel(log.getDebug()) >= log.DEBUG:
 
422
        if log.getCategoryLevel(self.logCategory) >= log.DEBUG:
413
423
            fd, path = tempfile.mkstemp(suffix='.html')
414
424
            os.write(fd, response)
415
425
            os.close(fd)
416
426
            self.debug("Response written to %r", path)
417
427
 
418
 
        # FIXME: this is awful. Requires discussions with Rafal &
419
 
        # Xose. This if should not be needed when server returns
420
 
        # proper serialized error_models.
421
 
        if response and response not in ('{"response": "OK"}',
422
 
                                         '{"response": "NOK"}'):
 
428
        if response not in ('{"response": "OK"}',):
423
429
            factory = self.model_factory
424
430
            model = factory.create_model_for_serial_id(response, api_version,
425
431
                                                       serial_id)
428
434
 
429
435
    def _unwrap_response(self, result_model):
430
436
        if result_model.code == responsecode.UNAUTHORIZED:
431
 
            return Failure(Exception('%d - Unauthorized' % result_model.code))
 
437
            raise Exception('%d - Unauthorized' % result_model.code)
432
438
        elif result_model.error_model is not None:
433
439
            # The server returned an error response, wrap this in a failure
434
 
            return Failure(Exception(result_model.error_model.description))
 
440
            raise APIResponseError(result_model.error_model)
435
441
        else:
436
442
            return result_model.response_model