mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
6dc053e55c
Rework how errors are propagated from the daemon code to the HTTP client, creating an exception hierarchy to handle the most common cases.
34 lines
918 B
Python
34 lines
918 B
Python
#
|
|
# This file is distributed under the MIT License. See LICENSE.md for details.
|
|
#
|
|
|
|
|
|
class DaemonException(Exception):
|
|
"""
|
|
An exception that a route can raise to do an early-exit with
|
|
some data and a status code.
|
|
"""
|
|
|
|
def __init__(self, code: int, body: dict):
|
|
self.code = code
|
|
self.body = {"type": self.__class__.__name__, **body}
|
|
|
|
|
|
class EpochError(DaemonException):
|
|
def __init__(self, current_epoch: int, provided_epoch: int):
|
|
super().__init__(
|
|
409,
|
|
{
|
|
"expected_epoch": current_epoch,
|
|
"message": (
|
|
f"Epoch mismatch: client has epoch {provided_epoch}, "
|
|
f"server has epoch {current_epoch}."
|
|
),
|
|
},
|
|
)
|
|
|
|
|
|
class MalformedRequestError(DaemonException):
|
|
def __init__(self, message: str):
|
|
super().__init__(400, {"message": message})
|