diff --git a/code/api/client.py b/code/api/client.py index 042f7b8..b0ca2b3 100644 --- a/code/api/client.py +++ b/code/api/client.py @@ -2,7 +2,7 @@ from ssl import SSLCertVerificationError import requests -from requests.exceptions import SSLError +from requests.exceptions import SSLError, InvalidHeader from api.errors import ( SSLCertificateVerificationFailedError, @@ -11,6 +11,9 @@ ) +AUTHORIZATION_FAILED = "Authorization failed on AlienVault OTX side" + + class Client: def __init__(self, key, url, headers=None, params=None): @@ -38,14 +41,14 @@ def query(self, endpoint, headers=None, params=None): getattr(error, 'verify_message', error.args[0]).capitalize() ) raise SSLCertificateVerificationFailedError(reason=reason) + except (InvalidHeader, UnicodeEncodeError): + raise AuthenticationRequiredError(reason=AUTHORIZATION_FAILED) if response.status_code == HTTPStatus.BAD_REQUEST: return None if response.status_code == HTTPStatus.FORBIDDEN: - raise AuthenticationRequiredError( - reason="Authorization failed on AlienVault OTX side" - ) + raise AuthenticationRequiredError(reason=AUTHORIZATION_FAILED) if response.status_code == HTTPStatus.NOT_FOUND: return None diff --git a/code/app.py b/code/app.py index c159dea..1ffa8ef 100644 --- a/code/app.py +++ b/code/app.py @@ -1,10 +1,11 @@ +import traceback + from flask import Flask, jsonify from api.enrich import enrich_api from api.health import health_api from api.version import version_api from api.watchdog import watchdog_api - from api.errors import RelayError from api.utils import jsonify_errors @@ -21,13 +22,13 @@ @app.errorhandler(RelayError) def handle_relay_error(error): - app.logger.error(error.json()) + app.logger.error(traceback.format_exc()) return jsonify_errors(error) @app.errorhandler(Exception) def handle_error(exception): - app.logger.error(exception) + app.logger.error(traceback.format_exc()) code = getattr(exception, 'code', 500) message = getattr(exception, 'description', 'Something went wrong.') reason = '.'.join([ diff --git a/code/container_settings.json b/code/container_settings.json index c889bdc..fe111cc 100644 --- a/code/container_settings.json +++ b/code/container_settings.json @@ -1,4 +1,4 @@ { - "VERSION": "2.0.3", + "VERSION": "2.0.4", "NAME": "AlienVault OTX" }