From cd4131e890bc9abe8bbedab726b8bed5acb9ef4e Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 11 Jan 2021 22:12:31 +0200 Subject: [PATCH] Exceptions: make sure error codes aren't None. --- etebase_fastapi/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etebase_fastapi/exceptions.py b/etebase_fastapi/exceptions.py index 61e4439..d38d50a 100644 --- a/etebase_fastapi/exceptions.py +++ b/etebase_fastapi/exceptions.py @@ -72,7 +72,7 @@ class HttpError(CustomHttpException): errors: t.Optional[t.List["HttpError"]] = None, ): self.errors = errors - super().__init__(code=code, detail=detail, status_code=status_code) + super().__init__(code=code or "generic_error", detail=detail, status_code=status_code) @property def as_dict(self) -> dict: @@ -104,7 +104,7 @@ def flatten_errors(field_name: str, errors) -> t.List[HttpError]: message = error.messages[0] else: message = str(error) - ret.append(ValidationError(code=error.code, detail=message, field=field_name)) + ret.append(ValidationError(code=error.code or "validation_error", detail=message, field=field_name)) return ret