Skip to content

Commit

Permalink
bugfix/enhanced the error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hongwei1 committed Nov 29, 2023
1 parent 6b54d4a commit ff2b203
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 50 deletions.
6 changes: 0 additions & 6 deletions apimanager/banks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def get_form(self, *args, **kwargs):
fields['bank_routings_scheme'].initial = result['bank_routings'][0]["scheme"]
fields['bank_routings_address'].initial = result['bank_routings'][0]["address"]
except Exception as err:
if DEBUG:
raise(err)
messages.error(self.request, "Unknown Error {}".format(err))
return form

Expand All @@ -138,13 +136,9 @@ def form_valid(self, form):
messages.error(self.request, result['message'])
return super(UpdateBanksView, self).form_invalid(form)
except APIError as err:
if DEBUG:
raise(err)
messages.error(self.request, err)
return super(UpdateBanksView, self).form_invalid(form)
except Exception as e:
if DEBUG:
raise(err)
messages.error(self.request, e)
return super(UpdateBanksView, self).form_invalid(form)
msg = 'Bank {} has been updated successfully!'.format( # noqa
Expand Down
4 changes: 2 additions & 2 deletions apimanager/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_consumers(request):
else:
return []
except APIError as err:
messages.error(self.request, err)
messages.error(request, err)
return []

def get_api_versions(request):
Expand All @@ -44,7 +44,7 @@ def get_api_versions(request):
else:
return []
except APIError as err:
messages.error(self.request, err)
messages.error(request, err)
return []

class HomeView(TemplateView):
Expand Down
42 changes: 0 additions & 42 deletions apimanager/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,10 @@ def get_metrics(self, cleaned_data):
metrics = api.get(urlpath)
metrics = self.to_django(metrics['metrics'])
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except KeyError as err:
if DEBUG:
raise(err)
error_once_only(self.request, metrics['message'])
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
return metrics

Expand Down Expand Up @@ -352,12 +346,8 @@ def get_aggregate_metrics(self, from_date, to_date, include_app_names):
api_calls_total, average_response_time, cache_key, from_date, metrics, to_date, url_path)
return api_calls_total, average_response_time, int(average_calls_per_day)
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)

def get_internal_api_call_metrics(self, api_calls_total, average_response_time, cache_key, from_date, metrics,
Expand Down Expand Up @@ -389,8 +379,6 @@ def get_active_apps(self, from_date, to_date):
except APIError as err:
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
else:
urlpath = '/management/metrics/top-consumers?from_date={}&to_date={}&exclude_implemented_by_partial_functions={}&exclude_url_pattern={}'.format(
Expand All @@ -400,12 +388,8 @@ def get_active_apps(self, from_date, to_date):
apps = api.get(urlpath)
active_apps_list = list(apps['top_consumers'])
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)

return active_apps_list
Expand Down Expand Up @@ -469,12 +453,8 @@ def get_all_consumers(self):
LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_URL_MSG, urlpath))
LOGGER.warning('{0}: {1}'.format(CACHE_SETTING_KEY_MSG, cache_key))
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
return apps_list

Expand Down Expand Up @@ -504,8 +484,6 @@ def calls_per_delta(self, from_date_string, to_date_string, include_app_names, *
result_list.append('{} - {} # {}'.format(from_datetime_object, time_delta_in_loop, result))
date_list.append(from_datetime_object)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
break

Expand Down Expand Up @@ -688,8 +666,6 @@ def get_users_cansearchwarehouse(self):
except KeyError as err:
messages.error(self.request, 'KeyError: {}'.format(err))
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)

user_email_cansearchwarehouse = dict(zip(users_with_cansearchwarehouse, email_with_cansearchwarehouse))
Expand All @@ -714,12 +690,8 @@ def _api_data(self, urlpath, data_key):
else:
data = data[data_key]
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
return data

Expand Down Expand Up @@ -772,12 +744,8 @@ def get_top_warehouse_calls(self, cleaned_data, from_date, to_date):
if "elasticSearchWarehouse" in api['Implemented_by_partial_function']:
top_warehouse_calls.append(api)
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
return top_warehouse_calls

Expand All @@ -795,12 +763,8 @@ def get_top_apps_using_warehouse(self, from_date, to_date):
else:
top_apps_using_warehouse = top_apps_using_warehouse["top_consumers"][:2]
except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)

return top_apps_using_warehouse
Expand Down Expand Up @@ -857,12 +821,8 @@ def median_time_to_first_api_call(self, from_date, to_date):


except APIError as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, 'Unknown Error. {}'.format(err))

if times_to_first_call:
Expand Down Expand Up @@ -980,8 +940,6 @@ def prepare_general_context(self, web_page_type, **kwargs):
else:
error_once_only(self.request, str(form.errors))
except Exception as err:
if DEBUG:
raise(err)
error_once_only(self.request, err)
def _daily_and_weekly(self, web_page_type,to_date, per_hour_chart, per_day_chart, from_date):
if (web_page_type == SummaryType.DAILY):
Expand Down

0 comments on commit ff2b203

Please sign in to comment.