From 92b94b59ad80329a2c99471edbf5bbdc9af1e525 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 26 Jun 2020 12:17:26 +0200 Subject: Revamp error responses --- opendc/util/rest.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'opendc/util/rest.py') diff --git a/opendc/util/rest.py b/opendc/util/rest.py index 33371e52..e70998a8 100644 --- a/opendc/util/rest.py +++ b/opendc/util/rest.py @@ -6,6 +6,7 @@ import sys from oauth2client import client, crypt from opendc.util import exceptions, parameter_checker +from opendc.util.exceptions import ClientRequestError class Request(object): @@ -71,14 +72,22 @@ class Request(object): def check_required_parameters(self, **kwargs): """Raise an error if a parameter is missing or of the wrong type.""" - parameter_checker.check(self, **kwargs) + try: + parameter_checker.check(self, **kwargs) + except exceptions.ParameterError as e: + raise ClientRequestError(Response(400, str(e))) def process(self): """Process the Request and return a Response.""" method = getattr(self.module, self.method) - response = method(self) + try: + response = method(self) + except ClientRequestError as e: + e.response.id = self.id + return e.response + response.id = self.id return response -- cgit v1.2.3