""" Result ======== A result encapsulates the outcome of a call to the logic layer. The result contains 3 fields: message (data), errors (any errors found) and a status. Although the status values correspond to HTTP status codes, a result object is not necessarily meant to represent an HTTP response. Crafting an HTTP response is a responsibility of the controller and not the logic layer, and a result object can be consumed by a non-HTTP caller such as a CLI script or a queue consumer, as well as by a controller. The message property can be any type of object. The exact type of the object is part of the contract between the service that creates the result and the caller that consumes it. This is modeled after the Response class in grass. """ class Result: def __init__(self, message=None, errors=None, status=200): self.message = message self.errors = errors or {} self.status = status @property def success(self): return 200 <= self.status < 300 def create_fatal_result(errors=None): return Result(errors=errors, status=500) def create_error_result(errors=None): return Result(errors=errors, status=400)