exceptions.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import json
  18. import logging
  19. from desktop.lib.exceptions import StructuredException
  20. from desktop.lib.rest.http_client import RestException
  21. LOG = logging.getLogger(__name__)
  22. class PermissionDeniedException(StructuredException):
  23. def __init__(self, msg, orig_exc=None):
  24. # TODO(todd) use orig_exc for something fun
  25. StructuredException.__init__(self,
  26. "PERMISSION_DENIED",
  27. msg)
  28. class WebHdfsException(RestException):
  29. def __init__(self, error):
  30. RestException.__init__(self, error)
  31. try:
  32. json_body = json.loads(self._message)['RemoteException']
  33. self.server_exc = json_body['exception']
  34. self._message = "%s: %s" % (self.server_exc, json_body['message'])
  35. except:
  36. LOG.exception('failed to parse remote exception')
  37. # Don't mask the original exception
  38. self.server_exc = None