Skip to content

Commit

Permalink
[fix] Added Raise after exception connection error nlp
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jul 11, 2019
1 parent b0498d4 commit d49fab9
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.template.loader import render_to_string
from django.dispatch import receiver
from django.core.exceptions import ValidationError
from rest_framework import status
from rest_framework.exceptions import APIException

from bothub.authentication.models import User

Expand Down Expand Up @@ -203,14 +205,19 @@ def request_nlp_analyze(cls, user_authorization, data):

@classmethod
def request_nlp_evaluate(cls, user_authorization, data):
r = requests.post( # pragma: no cover
cls.nlp_evaluate_url,
data={
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
try: # pragma: no cover
r = requests.post( # pragma: no cover
cls.nlp_evaluate_url,
data={
'language': data.get('language'),
},
headers={'Authorization': 'Bearer {}'.format(
user_authorization.uuid)})
return r # pragma: no cover
except requests.exceptions.ConnectionError: # pragma: no cover
raise APIException( # pragma: no cover
{'status_code': status.HTTP_503_SERVICE_UNAVAILABLE},
code=status.HTTP_503_SERVICE_UNAVAILABLE)

@property
def available_languages(self):
Expand Down

0 comments on commit d49fab9

Please sign in to comment.