示例#1
0
 def find_unique(self, **kwargs):
     found = self.find(**kwargs)
     if not found:
         raise APIException(error_code=404,
                            error_message=_("No matches found."))
     if len(found) > 1:
         raise APIException(error_code=409,
                            error_message=_("Multiple matches found."))
     return found[0]
示例#2
0
 def find_unique(self, **kwargs):
     found = self.find(**kwargs)
     if not found:
         raise APIException(error_code=404,
                            error_message=_("No matches found."))
     if len(found) > 1:
         raise APIException(error_code=409,
                            error_message=_("Multiple matches found."))
     return found[0]
示例#3
0
    def _raise_api_exception(self, resp):
        try:
            error_data = get_json(resp)
        except Exception:
            msg = _("Failed to parse response from Sahara: %s") % resp.reason
            raise APIException(error_code=resp.status_code, error_message=msg)

        raise APIException(error_code=error_data.get("error_code"),
                           error_name=error_data.get("error_name"),
                           error_message=error_data.get("error_message"))
示例#4
0
    def _raise_api_exception(self, resp):
        try:
            error_data = get_json(resp)
        except Exception:
            msg = _("Failed to parse response from Sahara: %s") % resp.reason
            raise APIException(
                error_code=resp.status_code,
                error_message=msg)

        raise APIException(error_code=error_data.get("error_code"),
                           error_name=error_data.get("error_name"),
                           error_message=error_data.get("error_message"))