-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP WIP * WIP * WIP * search
- Loading branch information
Showing
21 changed files
with
4,532 additions
and
4,740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"include": [ | ||
"./assets/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"./assets/bundles/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .es import init_es | ||
|
||
es = init_es() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import logging | ||
from django.conf import settings | ||
from elasticsearch import Elasticsearch | ||
from elasticsearch_dsl.connections import connections | ||
|
||
logger = logging.getLogger(settings.APP_NAME) | ||
|
||
def init_es() -> Elasticsearch: | ||
logger.info("Connecting to elasticsearch...") | ||
# this creates the global connection pool to elasticsearch | ||
return connections.create_connection(hosts=[settings.ES_HOST,]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class KerckhoffCustomException(Exception): | ||
status_code = None | ||
error_message = None | ||
is_an_error_response = True | ||
def __init__(self, error_message): | ||
Exception.__init__(self) | ||
self.error_message = error_message | ||
def to_dict(self): | ||
return {'message': self.error_message} | ||
|
||
class UserError(KerckhoffCustomException): | ||
status_code = 400 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.http import JsonResponse | ||
from django.conf import settings | ||
from django.utils.deprecation import MiddlewareMixin | ||
import logging | ||
import traceback | ||
|
||
logger = logging.getLogger(settings.APP_NAME) | ||
|
||
def is_registered(exception: Exception): | ||
try: | ||
return exception.is_an_error_response | ||
except AttributeError: | ||
return False | ||
|
||
class RequestExceptionMiddleware(MiddlewareMixin): | ||
def process_exception(self, request, exception): | ||
if is_registered(exception): | ||
status = exception.status_code | ||
exception_dict = exception.to_dict() | ||
else: | ||
status = 500 | ||
exception_dict = {'message': 'Unexpected server error'} | ||
logger.error("ERROR 500 - %s" % traceback.format_exc()) | ||
if settings.DEBUG: | ||
raise exception | ||
|
||
return JsonResponse(exception_dict, status=status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.