Skip to content

Commit

Permalink
[CCTRI-3430] handle error caused by cyrillic symbol or space in 'key' (
Browse files Browse the repository at this point in the history
…#52)

* [CCTRI-3430] handle error caused by cyrillic symbol or space in 'key'

* [CCTRI-3413] add traceback to log file
  • Loading branch information
mstoro authored Dec 7, 2021
1 parent 0c7982d commit 28d90bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions code/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -11,6 +11,9 @@
)


AUTHORIZATION_FAILED = "Authorization failed on AlienVault OTX side"


class Client:

def __init__(self, key, url, headers=None, params=None):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions code/app.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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([
Expand Down

0 comments on commit 28d90bc

Please sign in to comment.