From ed9fc266c00882910313f6ff00940eeff2f1f650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADn=20Sempere?= Date: Wed, 5 Oct 2022 12:56:03 +0200 Subject: [PATCH 1/2] #312 update error handler to handle different type of exceptions --- CHANGELOG.md | 2 ++ prom2teams/app/api.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8ccde1..3a51805 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +### Added +- *[#312](https://github.com/idealista/prom2teams/pull/312) Improve error handler to distinguish between different kind of exceptions* @smartinsempere ## [4.1.0](https://github.com/idealista/prom2teams/tree/4.1.0) [Full Changelog](https://github.com/idealista/prom2teams/compare/4.0.0...4.1.0) ### Fixed diff --git a/prom2teams/app/api.py b/prom2teams/app/api.py index e19f99c..edf7121 100644 --- a/prom2teams/app/api.py +++ b/prom2teams/app/api.py @@ -2,8 +2,10 @@ import os from flask import Flask, Blueprint, send_from_directory +from marshmallow.exceptions import ValidationError from prom2teams.app.configuration import config_app, setup_logging +from .exceptions import MicrosoftTeamsRequestException from .versions.v1 import api_v1 from .versions.v1.namespace import ns as ns_v1 from .versions.v2 import api_v2 @@ -13,26 +15,33 @@ app = Flask(__name__) + @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') + @app.route('/alive') def alive(): return "YES", 200 + @app.route('/ready') def ready(): return ("YES", 200) if app.config['FINISH_INIT'] else ("NO", 503) + def error_handler(e): msg = 'An unhandled exception occurred. {}'.format(e) log.exception(msg) + if isinstance(e, MicrosoftTeamsRequestException): + return str(e), e.code + if isinstance(e, ValidationError): + return str(e), 400 return str(e), 500 - def register_api(application, api, namespace, blueprint): api.init_app(blueprint) api.add_namespace(namespace) @@ -50,5 +59,6 @@ def init_app(application): application.register_error_handler(500, error_handler) application.config['FINISH_INIT'] = True + init_app(app) log.info('{} started on {}:{}'.format(app.config['APP_NAME'], app.config['HOST'], app.config['PORT'])) From d2bc1cc50a116c29b456e8daa6c1b7d2a1359f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADn=20Sempere?= Date: Wed, 5 Oct 2022 15:22:40 +0200 Subject: [PATCH 2/2] update CHANGELOG.md --- CHANGELOG.md | 2 ++ helm/Chart.yaml | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a51805..e86fb56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a changelog](https://github.com/olivierlacan/keep-a-changelog). ## [Unreleased](https://github.com/idealista/prom2teams/tree/develop) +## [4.2.0](https://github.com/idealista/prom2teams/tree/4.2.0) +[Full Changelog](https://github.com/idealista/prom2teams/compare/4.1.0...4.2.0) ### Added - *[#312](https://github.com/idealista/prom2teams/pull/312) Improve error handler to distinguish between different kind of exceptions* @smartinsempere ## [4.1.0](https://github.com/idealista/prom2teams/tree/4.1.0) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index e5427f6..22a7d7d 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 -appVersion: "3.2.3" +appVersion: "4.2.0" description: A Helm chart for Prom2Teams name: prom2teams version: 0.2.0 diff --git a/setup.py b/setup.py index 674c51f..ca975d6 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup(name='prom2teams', - version='3.3.0', + version='4.2.0', description='Project that redirects Prometheus Alert Manager ' 'notifications to Microsoft Teams', long_description=readme,