Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
webservices
cern-search
cern-search-rest-api
Commits
f3342f90
Commit
f3342f90
authored
Mar 11, 2019
by
Pablo Panero
Browse files
views: add mapper parsing exceptions handling
parent
ef58f1b7
Changes
3
Show whitespace changes
Inline
Side-by-side
cern_search_rest_api/config.py
View file @
f3342f90
...
...
@@ -13,6 +13,7 @@ import ast
import
copy
import
os
from
invenio_oauthclient.contrib
import
cern
from
invenio_records_rest
import
config
as
irr_config
from
.modules.cernsearch.permissions
import
(
record_read_permission_factory
,
record_create_permission_factory
,
...
...
@@ -113,6 +114,11 @@ RECORDS_REST_ENDPOINTS = dict(
)
)
RECORDS_REST_ELASTICSEARCH_ERROR_HANDLERS
=
copy
.
deepcopy
(
irr_config
.
RECORDS_REST_ELASTICSEARCH_ERROR_HANDLERS
)
RECORDS_REST_ELASTICSEARCH_ERROR_HANDLERS
[
'mapper_parsing_exception'
]
=
\
'cern_search_rest_api.modules.cernsearch.views:elasticsearch_mapper_parsing_exception_handler'
# App
# ===
...
...
cern_search_rest_api/modules/cernsearch/errors.py
0 → 100644
View file @
f3342f90
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019, CERN
# This software is distributed under the terms of the GNU General Public
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".
# In applying this license, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as Intergovernmental Organization
# or submit itself to any jurisdiction.
from
invenio_rest.errors
import
RESTValidationError
class
InvalidRecordFormatError
(
RESTValidationError
):
"""Invalid query syntax."""
code
=
400
description
=
'Invalid query syntax.'
\ No newline at end of file
cern_search_rest_api/modules/cernsearch/views.py
View file @
f3342f90
...
...
@@ -31,9 +31,18 @@ from invenio_records_rest.views import need_record_permission, pass_record
from
invenio_rest
import
ContentNegotiatedMethodView
from
invenio_search
import
current_search_client
from
invenio_indexer.utils
import
default_record_to_index
from
cern_search_rest_api.modules.cernsearch.errors
import
InvalidRecordFormatError
from
cern_search_rest_api.modules.cernsearch.search
import
RecordCERNSearch
def
elasticsearch_mapper_parsing_exception_handler
(
error
):
"""Handle mapper parsing exceptions from ElasticSearch."""
description
=
'The format of the record is invalid. {reason}.'
\
'{caused_by}'
.
format
(
reason
=
error
.
info
[
'error'
][
'root_cause'
],
caused_by
=
error
.
info
[
'error'
][
'caused_by'
][
'reason'
]
)
return
InvalidRecordFormatError
(
description
=
description
).
get_response
()
def
create_error_handlers
(
blueprint
):
"""Create error handlers on blueprint."""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment