Esempio n. 1
0
def validate_query_params(limit, sort_keys, sort_dirs):
    if limit is not None and limit <= 0:
        raise wsme_exc.ClientSideError("Limit must be positive.")

    if len(sort_keys) < len(sort_dirs):
        raise wsme_exc.ClientSideError(
            "Length of sort_keys must be equal or greater than sort_dirs.")

    if len(sort_keys) > len(sort_dirs):
        sort_dirs.extend(['asc'] * (len(sort_keys) - len(sort_dirs)))

    for sort_dir in sort_dirs:
        if sort_dir not in ['asc', 'desc']:
            raise wsme_exc.ClientSideError(
                "Unknown sort direction, must be 'desc' or 'asc'.")
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except ex.LBaaSException as excp:
         pecan.response.translatable_error = excp
         raise exc.ClientSideError(msg=six.text_type(excp),
                                   status_code=excp.http_code)
Esempio n. 3
0
    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except (exc.MistralException, exc.MistralError) as e:
            pecan.response.translatable_error = e

            raise wsme_exc.ClientSideError(msg=six.text_type(e),
                                           status_code=e.http_code)
Esempio n. 4
0
    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except exc.QinlingException as e:
            pecan.response.translatable_error = e

            LOG.error('Error during API call: %s', six.text_type(e))
            raise wsme_exc.ClientSideError(msg=six.text_type(e),
                                           status_code=e.http_code)
Esempio n. 5
0
    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except (exc.MistralException, exc.MistralError) as e:
            pecan.response.translatable_error = e

            LOG.error('Error during API call: %s', str(e))

            raise wsme_exc.ClientSideError(msg=str(e), status_code=e.http_code)
Esempio n. 6
0
def validate_fields(fields, object_fields):
    """Check for requested non-existent fields.

    Check if the user requested non-existent fields.

    :param fields: A list of fields requested by the user.
    :param object_fields: A list of fields supported by the object.
    """
    if not fields:
        return

    invalid_fields = set(fields) - set(object_fields)

    if invalid_fields:
        raise wsme_exc.ClientSideError('Field(s) %s are invalid.' %
                                       ', '.join(invalid_fields))
Esempio n. 7
0
def validate_fields(fields, object_fields):
    """Check for requested non-existent fields.

    Check if the user requested non-existent fields.

    :param fields: A list of fields requested by the user.
    :param object_fields: A list of fields supported by the object.
    """
    if not fields:
        return

    invalid_fields = set(fields) - set(object_fields)

    if invalid_fields:
        raise wsme_exc.ClientSideError(
            'Some fields do not exist  [%s], please choose from [%s]' %
            (', '.join(invalid_fields), ', '.join(object_fields)))
Esempio n. 8
0
 def test_format_client_exception_unicode(self):
     faultstring = u'\xc3\xa3o'
     ret = self._test_format_exception(exc.ClientSideError(faultstring))
     self.assertIsNone(ret['debuginfo'])
     self.assertEqual('Client', ret['faultcode'])
     self.assertEqual(faultstring, ret['faultstring'])