Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.73'
__version__ = '1.2.74'
18 changes: 14 additions & 4 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from namex.services.name_request import NameRequestService
from namex.services.name_request.name_request import get_nrs_like_names, get_nrs_like_nr_num
from namex.services.name_request.utils import check_ownership, get_or_create_user_by_jwt, valid_state_transition
from namex.services.solr.solr_client import SolrClient
from namex.services.solr.solr_client import QUERY_TOO_COMPLEX, SolrClient, SolrClientException
from namex.services.solr.solr_helpers import SolrHlpers
from namex.utils import queue_util
from namex.utils.auth import cors_preflight
Expand Down Expand Up @@ -1453,16 +1453,26 @@ class PossibleConflicts(Resource):
responses={
200: 'Conflict results fetched successfully',
401: 'Unauthorized',
422: 'Query too complex for conflict search',
500: 'Internal server error',
},
)
def get(name):
start = request.args.get('start', PossibleConflicts.START)
rows = request.args.get('rows', PossibleConflicts.ROWS)
exact_phrase = str(request.args.get('exact_phrase', '')).strip()
results = SolrHlpers.get_possible_conflicts(
name, start=start, rows=rows, exact_phrase=exact_phrase
)
try:
results = SolrHlpers.get_possible_conflicts(
name, start=start, rows=rows, exact_phrase=exact_phrase
)
except SolrClientException as err:
body = err.body if isinstance(err.body, dict) else {}
if body.get('code') == QUERY_TOO_COMPLEX:
payload = {'code': QUERY_TOO_COMPLEX}
if body.get('message'):
payload['message'] = body['message']
return make_response(jsonify(payload), err.status_code or 422)
raise
return make_response(jsonify(results), 200)


Expand Down
13 changes: 12 additions & 1 deletion api/namex/services/solr/solr_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from namex.utils.auth import get_client_credentials

QUERY_TOO_COMPLEX = 'QUERY_TOO_COMPLEX'


class SolrClientException(Exception):
def __init__(self, wrapped_err=None, body=None, message='Solr client exception', status_code=500):
Expand Down Expand Up @@ -79,7 +81,16 @@ def get_possible_conflicts(cls, name, start=0, rows=100, exact_phrase=''):
headers={'Authorization': f'Bearer {token}'}
)
if resp.status_code != 200:
raise SolrClientException(message=f'Solr search failed: {resp.text}', status_code=resp.status_code)
body = None
try:
body = resp.json()
except ValueError:
body = None
raise SolrClientException(
body=body,
message=f'Solr search failed: {resp.text}',
status_code=resp.status_code,
)

return resp.json()

Expand Down
2 changes: 1 addition & 1 deletion api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "namex"
version = "1.50.2"
version = "1.50.3"
description = ""
authors = ["Thor Wolpert <thor@wolpert.ca>"]
license = "Apache Software License Version 2.0"
Expand Down
Loading