From d2c2e1b671a6f4d58bd43162018ddd0df011a5de Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 27 Jan 2024 20:20:47 +0900 Subject: [PATCH] Catch specific exception when validating time zone ... instead of the generic Exception to avoid hiding unexpected errors. Change-Id: I5200e097bec2e0bd43f25a3c457391b10f913930 --- aodh/api/controllers/v2/alarms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aodh/api/controllers/v2/alarms.py b/aodh/api/controllers/v2/alarms.py index feae4f6f2..dadbeed5f 100644 --- a/aodh/api/controllers/v2/alarms.py +++ b/aodh/api/controllers/v2/alarms.py @@ -31,6 +31,7 @@ from oslo_utils import uuidutils import pecan from pecan import rest import pytz +import pytz.exceptions from stevedore import extension from urllib import parse as urlparse import wsme @@ -177,7 +178,7 @@ class AlarmTimeConstraint(base.Base): if tc.timezone: try: pytz.timezone(tc.timezone) - except Exception: + except pytz.exceptions.UnknownTimeZoneError: raise base.ClientSideError(_("Timezone %s is not valid") % tc.timezone) return tc