64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
|
|
class DeckhandException(Exception):
|
|
"""Base Deckhand Exception
|
|
To correctly use this class, inherit from it and define
|
|
a 'msg_fmt' property. That msg_fmt will get printf'd
|
|
with the keyword arguments provided to the constructor.
|
|
"""
|
|
msg_fmt = "An unknown exception occurred."
|
|
code = 500
|
|
|
|
def __init__(self, message=None, **kwargs):
|
|
self.kwargs = kwargs
|
|
|
|
if 'code' not in self.kwargs:
|
|
try:
|
|
self.kwargs['code'] = self.code
|
|
except AttributeError:
|
|
pass
|
|
|
|
if not message:
|
|
try:
|
|
message = self.msg_fmt % kwargs
|
|
|
|
except Exception:
|
|
message = self.msg_fmt
|
|
|
|
self.message = message
|
|
super(DeckhandException, self).__init__(message)
|
|
|
|
def format_message(self):
|
|
return self.args[0]
|
|
|
|
|
|
class ApiError(Exception):
|
|
pass
|
|
|
|
|
|
class InvalidFormat(ApiError):
|
|
"""The YAML file is incorrectly formatted and cannot be read."""
|
|
|
|
|
|
class DocumentExists(DeckhandException):
|
|
msg_fmt = ("Document with kind %(kind)s and schemaVersion "
|
|
"%(schema_version)s already exists.")
|
|
|
|
|
|
class RevisionNotFound(DeckhandException):
|
|
msg_fmt = ("The requested revision %(revision)s was not found.")
|
|
code = 403
|