+
+
+class ProblemDetails(Serializer):
+ def __init__(self, namespace: O2Namespace, code: int, detail: str,
+ title=None, instance=None
+ ) -> None:
+ self.ns = namespace
+ self.status = code
+ self.detail = detail
+ self.type = request.path
+ self.title = title if title is not None else self.getTitle(code)
+ self.instance = instance if instance is not None else []
+
+ def getTitle(self, code):
+ return HTTPStatus(code).phrase
+
+ def abort(self):
+ self.ns.abort(self.status, self.detail, **self.serialize())
+
+ def serialize(self):
+ details = {}
+ for key in dir(self):
+ if key == 'ns' or key.startswith('__') or\
+ callable(getattr(self, key)):
+ continue
+ else:
+ details[key] = getattr(self, key)
+ return details